laravellaravel-medialibrary

images not showing using spatie media library in Laravel 8


I am having trouble displaying the images uploaded using spatie media library. I already looked in their documentation but I can't find a solution.

I had no issue uploading files (single file only).

The Database Media Table screenshot of Database Media Table

Controller @ store

public function store(Request $request)
{
    $categories = new ProductCategories();
    $categories->name         = $request->name;
    $categories->slug         = $request->slug;
    $categories->description  = $request->description;

    if($request->hasFile('photo') && $request->file('photo')->isValid()){
        $categories->addMediaFromRequest('photo')->toMediaCollection('category');
    }

    $categories->save();
    $request->session()->flash('message', 'Successfully created category');
    return redirect()->back();
}

Controller @ index

public function index()
{
    $lists = ProductCategories::all();
    return view('dashboard\product_category\categoryList', [ 'lists' => $lists ]);
}

config/filesystems.php

'disks' => [
    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],
    'public' => [
        'driver' => 'local',
        'root' => public_path('images/media'),
        'url' => env('APP_URL').'/images/media',
        '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'),
    ],
],

config/media-library.php

'disk_name' => env('MEDIA_DISK', 'public'),

These are my media folders:

wamp64/www/butingting/public/images/media/2
wamp64/www/butingting/public/images/media/3
wamp64/www/butingting/public/images/media/4

Blade page

 @foreach ($lists as $list)
     <tr>
          <td>
              <img src="{{$list->getFirstMediaUrl('category')}}" width="120px"><br/>
              {{$list->getFirstMediaUrl('category')}}
          </td>
     </tr>
 @endforeach

If I add {{$list->getFirstMediaUrl('category')}}, it looks like this:

enter image description here

I already done the "php artisan storage:link"

any suggestions?


Solution

  • Thank you Lulzash and Mtxz for your time! I check and take a long stare at the env file :( specifically in APP_URL.

    The Solution is:

    Form APP_URL=localhost:8000 or APP_URL=https://localhost:8000

    It should be APP_URL=http://localhost:8000

    Thanks Mtxz because your question makes me decide to rethink about the APP_URL!