How to show uploaded images from storage dictory Hi,
I have just watched the video of uploading file with laravel 5.3. Everything is working fine and I can upload file to storange/avatars directory. How can I show those files in views? I mean, previously we used to use asset() function which was searching in public directory, How can we show the files from storage/avatars directory?
Thank's
should create symbolic link
php artisan storage:link
I usually create a StorageController to render storage files, this way i can set who can access or not the file, using middlewares or some code.
Class StorageController extends Controller
{
public function load($directory, $file)
{
if ($path = $this->fileExists($directory, $file)) {
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
}
}
}
@gabrielbuzzi
Imagine if you want to show the images in app.blade.php file, How would you do that?
Thanks
<img src="action('StorageController@load', 'users', 'me.jpg')" />
@gabrielbuzzi that's not working bro, It will output the exact same text in the src
@Hujjat you should put that inside the mustache
<img src="{{ action('StorageController@load', 'users', 'me.jpg') }}" />
@gabrielbuzzi
Again I got error.
'''
Action App\Http\Controllers\StorageController@load not defined. (View:
C:\Users\upplanet\Desktop\admin\resources\views\layouts\app.blade.php) (View:
C:\Users\upplanet\Desktop\admin\resources\views\layouts\app.blade.php)
'''
Here is my Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class StorageController extends Controller
{
public function load($directory, $file){
if ($path = $this->fileExists($directory, $file)) {
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
}
}
}
'''
Please sign in or create an account to participate in this conversation.