F
Filament8mo 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;
}
<?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
'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.
5 Replies
LeandroFerreira
LeandroFerreira8mo ago
console error?
tomc
tomcOP8mo ago
Hi @Leandro Ferreira this is what I get in my console "GET https://api.littdigitalacademy.org/storage/media/7081713f-d5c1-4ebc-abf4-d550e5cb98c8.png 404 (Not Found)" but in my local the image shows fine
LeandroFerreira
LeandroFerreira8mo ago
hum.. did you run php artisan storage:link ?
tomc
tomcOP8mo ago
yes I did run the storage:link command and it is working
tomc
tomcOP8mo ago
I realized that I can see the images in the other resources but it shows blank and throws a "Not Found" in the "filament-curator" media resource as well my API (http) resources, I think it has something to do with the url
No description
No description
Want results from more Discord servers?
Add your server