This is how I solved the problem of storing images in Laravel 5, so that only the viewed users can view the images. Non-authenticated people will be redirected to the login page. My server is a Ubuntu / Apache2 server.
Create the directory / var / www / YOURWEBSITE / app / Assets / Images
Add a route to the application /Http/routes.php.
Route::get('/images/{file}',' ImageController@getImage ');
Create a controller application /Http/Controllers/ImageController.php
<?php namespace App\Http\Controllers; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Auth; class ImageController extends Controller { public function __construct() { $this->middleware('auth'); } public function getImage($filename) { $path = '/var/www/YOURWEBSITE/app/Assets/Images/'.$filename; $type = "image/jpeg"; header('Content-Type:'.$type); header('Content-Length: ' . filesize($path)); readfile($path); } }
There are img tags in your view that have:
src="{{ url('/images/test.jpg') }}"
This, of course, assumes that test.jpg is a file in / var / www / YOURWEBSITE / app / Assets / Images /
Of course, you can add more logic, for example, do not hardcode the path to images, etc. This is just a simple example for authentication. Note the use of middleware ("auth") in the controller constructor.
source share