I deployed a Laravel Application with Laravel Forge and works fine except when I upload images to show in the application. I use this code to create a new record in a table. This new record have an "image" field where the URL of the image is stored. And the image should be stored in the "categories" folder.
$categoryword = Category::create([
'name' => $request->name,
'slug' => $request->slug,
'image' => Storage::put('categories', $request->file('image')),
'description' => $request->description,
'body' => $request->body,
'example' => $request->example,
'exception' => $request->exception,
'type' => "Ortographic Rules",
'clasification' => "Words",
'user_id' => auth()->user()->id
]);
Also, this is the code to show the image in a blade view:
<img id="image" name="image" src="{{ asset("storage/$categoryword->image")}}" alt="" height="400px" width="700px"/>
Locally, it works properly and images can be viewed. But when I try to upload a new record with an Image in production server with Laravel Forge I have this error:
Failed to load resource: the server responded with a status of 404 ()
In the production server I use:
php artisan storage:link
But when I enter to the public folder and enter to "storage" folder, that folder is empty.
But if I go to the "storage" folder which is in the same level of "public" folder inside my production server and I enter to that folder I have this three files:
app framework logs
And inside of "app" folder I have this two files:
public categories
So, "categories" folder where the images I upload are stored is in this location but I cannot show the images that I upload. How can I fix that and make the "storage" folder of "public" folder contains this "categories" folder? Sorry for my English
CodePudding user response:
I guess the problem was in the filesystems disk, so go to .env and change FILESYSTEM_DISK=local
to FILESYSTEM_DISK=public
.
Don't forget to add name of disk like that
Storage::disk('public')->put('categories', $request->file('image');