dimanche 11 novembre 2018

Laravel 5.7 storage:link images give 404 in production but works in valet

I'm reasonably new to Laravel and working on a project where I'm trying to figure out an issue I'm running into with trying to only keep images in storage/app/images and it's subdirectories. I thought I had done it according to documentation and it works as expected in my local environment running under Valet. When I promote it to my webserver however, running Nginx and php-fpm images don't display and if I click on the linkI get a 404 error.

Here is the disks section of filesystem.php

   'disks' => [

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

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

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

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

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

    ],

Here is the relevant code in the view:

@php
/* Grab a list of all images to dynamically display */
$files = Storage::disk('carousel')->files();
@endphp

<div class="flex-center position-ref">
    <div class="content">
        <div class="empty">
        </div>
        <div class="box-left">
            @include('partials/obit')
        </div>
                        <!-- Carousel Start  -->
        <div class="box-right">
             <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel" data-interval="5000" data-pause="hover">
              <div class="carousel-inner">
                @for($i=0; $i < count($files); $i++ )
                    @if ($i == 0)
                    <div class="carousel-item active">
                    @else
                    <div class="carousel-item">
                    @endif  
                    <img src="">
                </div>
                @endfor
             </div>

When I view source on the page it shows

<div class="carousel-item active">
<img src="http://www.example.com/images/carousel/01.jpg">
</div>
class="carousel-item">
<img src="http://www.example.com/images/carousel/03.JPG">

but clicking on those links give a 404. The only way I can get it to work in the production environment is to make a /images/carousel/ directory under app/public and copy the images there which is less than ideal as it's duplicating files and work.

Any idea what I'm doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire