I want to save images to a special directory, example – storage/private_files And show certain images to certain users after authorization. The user’s images will then have to be displayed in the IMG tag in the browser. Paths to files will be stored in the database in conjunction with the user. How to properly organize saving and serving images in Laravel 8.83.21?
2
Answers
You might consider using the temporary url function. If the user has access, you can create a temporary url for him and give the user access. And since the temporary url is expired, it cannot share the url with other users. This is the best way to handle file permissions:
Well, there’s a plenty of way to do it (middleware, policies, user_permissions, …).
What I would suggest (I don’t know what your model calls or the structure of your code, but when you get the idea apply it on yours):
config/filesystems.php
$file->storeAs("uploads", "image_x.jpg", "private");
Or using Storage FacadeExample of working with Policies