0

I Know there is a way to link storage folder in public folder, But I need another way.

So this is my question: is there any other way that I can display my images from storage folder without link it?

This is folders structure:

Storage->app->public->Categories->example.jpg

I need to display the images from the Categories folder several times in Vue3 FrontEnd.

1
  • wdu mean by link it ? Commented Aug 15, 2021 at 16:20

1 Answer 1

1

Yes, you can. Write a controller with image returning. Something like this (it's not production ready code, just concept).

class ImageController extends Controller
{
    public function __invoke($image_name)
    {
        $patch = 'Categories/'.$image_name.'.jpg';
        if(! Storage::exists($patch)){
             throw new HttpNotFoundException();
        }
        return response(Storage::get($patch))
            ->header('Content-Type', 'image/jpg');
    }
}

Route::get('images/{image_name}', ImageController::class);

<img src ="/images/example">
Sign up to request clarification or add additional context in comments.

2 Comments

its works but I have problem with the route, if route like that: localhost:8000/categories/images/Categories/… it work but it like that: localhost:8000/categories/27/images/Categories/… it return 404
Pls read documentation. If you want to define route with category id - just define it. laravel.com/docs/8.x/routing#route-parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.