Kishan
Kishan

Reputation: 1

File Upload component not showing image from Laravel local driver in Filament

I'm using FilamentPHP in my Laravel project. I'm using: FILESYSTEM_DISK and FILAMENT_FILESYSTEM_DISK local for store the file in storage. I've laravel seeder which creates some records in my DB and store images into storage/app/tool_photo_path folder. When I try to edit the tool then FileUpload component shows broken image, you can see attached image. I want to show image while edit the tool. When I use the public disk then it working fine but I want to use local driver. Image

I'm using below code for file upload as per filament built-in feature:

FileUpload::make('tool_photo_path')
                ->label('Tool photo')
                ->image()
                ->directory('tool_photo_path')
                ->required(),

Here my DB column name is tool_photo_path and folder name is also same. Now anyone can tell me how can I see uploaded image after refresh the page.

I've try with visibility feature given my Filament but nothing is working for me.

Upvotes: 0

Views: 694

Answers (2)

Kadir Bay
Kadir Bay

Reputation: 1

If we publish it in the public folder, people who have the link can openly view this file. For example: example.com/storage/files/abcd1234.png . Anyone can visit this link and view it.

I was advised to access via url using storage facede for this. not sure if it is the best solution.

Here is a code example.

Route::get('/storage/products/{path}', function ($path) {
        $path = 'products/' . $path;
        if (!Storage::disk('local')->exists($path)) {
            abort(404);
        }
    
        $file = Storage::disk('local')->get($path);
        $mimeType = Storage::disk('local')->mimeType($path);
    
        return Response::make($file, 200)->header("Content-Type", $mimeType);
})

Upvotes: 0

kristi tanellari
kristi tanellari

Reputation: 135

Make sure you've updated the APP_URL the url you're using for testing. For example if your app url on your .env file is localhost but your url in browser is localhost:8000 then the image isn't going to show. They have to match exactly. Also make you're you've run php artisan storage:link

Upvotes: 0

Related Questions