Laravel 5.3 - Issue displaying Images from public folder using @extends & @sections

前端 未结 3 888
再見小時候
再見小時候 2020-12-21 20:14

2nd Update:

For some reason the display: table; in my .header_table within home.blade.php was preventing the image from rendering.

3条回答
  •  庸人自扰
    2020-12-21 20:47

    Most convenient way to way to store and access images is by using Laravel filesystems.

    First you got to set up your file driver driver config/filesystems.php

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'visibility' => 'public',
    ],
    

    This will enable you to store your images in storage/app/public

    Lets say you are storing images in storage/app/public/your_storage_directory directory. So do as follows.

    $image = request()->file('banner');
    $path = $image->store('your_storage_directory', 'public');
    // persist $path in your table
    

    $path will contain someting simillar to your_storage_directory/3ca37bc0cdf2f71eeadf60057c71154b.jpeg

    Then do

    php artisan storage:link
    

    To create a symbolic link at public directory pointing to storage/app/public

    Then you only got to do is access the image from your blade file by using following syntax

    
    

提交回复
热议问题