I am having trouble showing images. I have stored images in:
nameproject/storage/images/2017/sep/
and I have created a link from the public folder:
ln -s storage/images public/images
and in my view:
<td><img src="{{ asset($post->image )}}" height="42" width="42"/></td>
but I receive the error:
GET https://challenge.local/images/2017/Sep/1504974522.jpeg 404 ()
try with this..images folder in public folder..
{{ URL::to('/images/2017/Sep/'.$post->image) }}
http://localhost/laraveltest/public/images/2017/Sep/1504974522.jpeg
Related
I have stored a image in my storage directory using spatie media package, the url to the image as returned by the getFullUrl() is http://127.0.0.1:8000/storage/34/conversions/download-thumb.jpg.
my APP_URL is APP_URL=http://127.0.0.1:8000
Then in in my blade file i'm using <img src="{{ $channel->image() }}" alt="">
And my function look like this
public function image() {
if($this->media->first())
{
return $this->media->first()->getFullUrl('thumb');
}
return null;
}
I'm not sure why my image is not showing on this url
I'm saving my uploaded image in public folder like
public/user/user_img_1.jpg
and saving
/user/user_img_1.jpg
in my database column as image path. Now when i get it
<img src="{{ $userData->thumb_img }}" alt="Profile Image" /> , the image shows on localhost but on server the image is not found. $userData variables stores the path.
We need to give permissions in Laravel for uploading and fetching the images.
Suppose you have saved the image in the public folder under the user folder.
Directory Path: public/user/
And save the image in Database like below:
key: thumb_img
value: "public/user/imagename.jpg"
{{ asset($userData->thumb_img) }}
You need to use the asset function for fetching the image.
Use asset function to generate a URL for an asset using the current scheme of the request.
In your case that would be: <img src="{{ asset($userData->thumb_img) }} alt="Profile Image" />
You have to do any one step :
Put all your files (img) into the public folder.
<img src="/user/{{ $userData->thum_img }}" alt="Profile Image" />
Or, Use asset helper :
<img src="/user/{{ asset($userData->thum_img) }}" alt="Profile Image" />
where user_img_1.jpg is path of your content.
This is my view:
<img src="../public/{{ $axid->img }}">
and this is my route :
Route::get('/ax/{axid}', function($id) {
$axid = show::find($id);
return view('ax', compact('axid'));
Images are uploaded in public/uploads and show is model name. However, I have this error:
NotFoundHttpException
...what is the problem?
If we assume that your image resolving code is functioning properly and that you are returning the full url of the image you want to show, then change your view code to:
<img src="{{ asset($axid->img) }}">
Please see how you should be setting this out:
View before moving to this a href..: Get ID
Route: Route::get('/ax/{id}', 'AxidController#get');
Controller with me assuming Show is your model name:
public function get($id, Show $show)
{
$axid = $show->find($id);
return view('page', compact('axid'));
}
On the page of ax/{id}:
<img src="{{ $axid->image }}">
Whenever I open an item the link would be
http://localhost/mywebsite/public/item/{$item_id}
the avatar will break. Below is the code I used
<img src="uploads/avatars/{{ Auth::user()->avatar }}">
The location of the image is C:\xampp\htdocs\mywebsite\public\uploads\avatars
I presume that as you are using relative URLs the translated path in browser will be http://localhost/mywebsite/public/item/{$item_id}/uploads/avatars/{{ Auth::user()->avatar }}
And that's not what you want
Try
<img src="http://localhost/mywebsite/public/uploads/avatars/{{ Auth::user()->avatar }}">
In production in will be just
<img src="/uploads/avatars/{{ Auth::user()->avatar }}">
Am not sure it will work on xampp though
So to say, I recommend using Laravel Valet or Homestead instead of Xampp, it cuts some problems like yours off.
in File model i created a function to get file encoded base64
public function getFile()
{
$path = storage_path('app'). "/" . $this->path;
$type = File::mimeType($path);
$file = Storage::disk('local')->get("/". $this->path);
return "data:image/png;base64,".base64_encode($file);
}
in blade You can use like that
<img src = '$file->getFile()'>
I have already uploaded the image in a folder and stored its path in the database field. I am trying to display image like this:
Controller:
public function showProfileImage($id)
{
$profileimage = UserProfileModel::where(['usrID' => $id])->first();
return view('userlogin::welcome')->with('profileimage', $profileimage->userPicpath);
}
my blade template has:
<img src="{{ route('showprofileimage', ['id' => Session::get('loggedinuserid')]) }}" height="150" />
But the path returned in the src is the route path, it doesn't contain the 'profileimage' path returned form the controller. How do i do this? Thanks
The route('<named route>') helper function returns the URL to a page/endpoint/resource that was defined as:
Route::get('some/uri', ['as' => 'showprofileimage', function() {
//
});
It may not be used for displaying images (although it could be used with a few tweaks), but I would go with either one of the following approaches:
If you have the fully qualified image URL then you can use the url() helper function. Do:
<img src="{{ url('showprofileimage') }}" ... />
If your image is in the /public directory, you can use the asset() helper function:
<img src="{{ asset('path/to/profile/image') }}" ... />
If your image is in the /storage directory, you can use the storage() helper function (but I believe this is not recommended):
<img src="{{ storage('path/to/profile/image') }}" ... />
Hope this helps. Cheers!