Laravel 5.4 Storage link

后端 未结 6 1633
温柔的废话
温柔的废话 2020-12-19 13:37

i would like to show a picture in html file i go to the link folder public/storage/image is empty but in the storage/image i find the file and its also saved in th

相关标签:
6条回答
  • 2020-12-19 14:08

    This worked for me. I added the command "Artisan::call('storage:link', [] );" to the beginning of the route file and deleted the storage folder from public.

    It is important to delete the folder first, otherwise it will not work.

    Removed the code from the route, if it is working, since it should only run once on the server.

    0 讨论(0)
  • 2020-12-19 14:09

    Go to public directory and run:

    rm storage
    

    Then go to project root and run:

    php artisan storage:link
    
    0 讨论(0)
  • 2020-12-19 14:13

    solved it with just a simple modification on the filesystems config/file systems from :

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

    to :

    'local' => [
                'driver' => 'local',
                'root' => storage_path('app/public'),
            ]
    
    0 讨论(0)
  • 2020-12-19 14:19

    The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. Laravel doc

    Create Symbolic link in Linux

    ln -s source_file myfile
    
    0 讨论(0)
  • As Mayank Majithya notes, a symbolic link is one common way to access storage/app/public/ files from the public/ directory, and in fact the method the Laravel docs say you should use.

    If you are on shared hosting that disallows this, you could also try to use Laravel's storage_path() helper function, like so: <img src="{{ storage_path('subpaths/under/storage/filename.jpg') }}"> (reference).

    I also notice you mention the images are stored in the database. If you mean the whole file is stored, it may be more efficient (once you have the file path figured out) to store only the file path in your database, rather than the whole file (since it is already stored on disk). You can then use your model to get the path (assuming your table has columns for, say, 'src' and 'alt'):

    <img src="{{ $mymodel->src }}" alt="{{ $mymodel->alt }}">
    
    0 讨论(0)
  • 2020-12-19 14:27

    First of all in the .env file create a variable named FILESYSTEM_DRIVER and set it to public like this

    FILESYSTEM_DRIVER=public
    

    and then create symbolic link by run

    php artisan storage:link
    

    after that just use asset()

    <img src="{{ asset('storage/'.$cv->photo) }}" alt="...">
    

    It'll work fine

    0 讨论(0)
提交回复
热议问题