community,
I have an issue with my Laravel application,
when saving images in my app, it works locally and keeps them in the correct directory, however, when I host the application to my server and try to test the application online, it now holds the images in the storage/app/ instead of the standard storage/app/public/ directory.
My storage link is in place and my function to save the image is also in place.
here is my filesystem setup
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
For example, let’s look at the save user process (using livewire).
$data["image"] = str_replace('public/', '', $this->image->store('users'));
$data["password"] = Hash::make("password");
$data['status'] = $data['status'] == 1 ? User::STATUS_ACTIVE : User::STATUS_INACTIVE;
$this->user->create($data);
$this->resetFields();
$this->emit("success", "User-created successfully!");
So the URL that is being generated afterwards looks like this
http://127.0.0.1:8000/storage/users/BYHZwuu03z4HikfcncH5hDdpjdbN7jPaQejbZ0fx.jpg
and to display this image,
<img src="{{ asset('storage/'.$user->image) }}" height="60px" width="60px"
class="rounded-pill">
When hosted online,the image doesnt display, and the link looks like this
http://{baseUrl(hidden)}/storage/users/eFJ8MLBUcREFlXpJQ5JvTQ4ZfeUYcxzB7Dc8IRy3.jpg
What could be the issue ?
Right now i don’t know why the image isnt displaying,
2
Answers
Go to /root_project folder and run command :
php artisan storage:link
Hope it helps you.
Perhaps on the hosting you need to create a link to access the files:
See more about this here