E
E
Eugene2021-01-20 17:50:33
Laravel
Eugene, 2021-01-20 17:50:33

Laravel: how to organize private storage of images?

Tell me, who can come across.
How to properly organize private storage of images.
Not just storage (which can be done through the disk), but storage and accessibility through the URL.
There is a CRM system and a closed chat, bulletin board, where images are displayed. But now they are all in the "public folder" - which is not good.

And if I store them through storage in a non-public folder, then there is no accessibility through the URL.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-01-20
@atachrus

You need to make a route, controller, whatever that will check access and return data, something like this:

public function image(Request $request, PrivateImage $image)
    {
        if (!<есть доступ>) {
            abort(404);
        }
        $path = "private_images/{$image['id']}.{$image['ext']}";
        return response(Storage::get($path))->header('Content-Type', Storage::mimeType($path));
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question