FilamentF
Filament2y ago
tomc

Curator Image Not Found (Production)

I am using curator but I am getting Not Found for image url in production, note that I am passing it through an API resource. However I can access the image fine in my localhost. below is my model;

model :
<?php

namespace App\Models;

use Awcodes\Curator\Models\Media;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Category extends Model
{
    use HasFactory;

      /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'slug',
        'image_id',
        'description',
        'is_active'
    ];

        /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'is_active' => 'boolean',
    ];

    public function image(): BelongsTo
    {
        return $this->belongsTo(Media::class, 'image_id', 'id');
    }

    public function courses(): HasMany
    {
        return $this->hasMany(Course::class);
    }

    public function getImageUrlAttribute()
    {
        // Check if image relationship is loaded
        if (!$this->relationLoaded('image')) {
            return config('app.placeholder_image_url'); 
        }
        // Access image URL through the relationship
        return $this->image->path;
    } 

and this is how I call it in my api resource;
'image' => $this->when(function () {
                return $this->relationLoaded('image');
            }, function () {
                return optional($this->image)->url; // Access url only if image exists
            }), // Include image URL only if image relationship is loaded 

kindly assist.
Was this page helpful?