FileUpload Image with morphOne relationship

I am trying to get the FileUpload field to work with all of the image morphOne relationships I have in my program. An example of one of the relationships is included below. FileUpload is being called on SchoolResource.php. School.php is related to ProgramOperator.php via the 'entity' relationship. I am guessing I am missing something painfully obvious somewhere. EntityImage.php
Class EntityImage extends Model {
protected $table = 'images';

protected static $storageBucket = 'entities';

protected static $sizes = array('800x600', '500x400', '200x150');
protected static $resize_method = 'resize';

public function __construct()
{

}

public function imageable(): MorphTo
{
return $this->morphTo();
}

public function getUrlAttribute()
{
return Storage::url('uploads/' . $this->bucket . '/' . $this->filename);
}
}
Class EntityImage extends Model {
protected $table = 'images';

protected static $storageBucket = 'entities';

protected static $sizes = array('800x600', '500x400', '200x150');
protected static $resize_method = 'resize';

public function __construct()
{

}

public function imageable(): MorphTo
{
return $this->morphTo();
}

public function getUrlAttribute()
{
return Storage::url('uploads/' . $this->bucket . '/' . $this->filename);
}
}
ProgramLogo.php
class ProgramLogo extends EntityImage {

protected static $storageBucket = 'programs';
protected static $sizes = array('800x800', '400x400', '128x128', '64x64', '32x32', '16x16');

}
class ProgramLogo extends EntityImage {

protected static $storageBucket = 'programs';
protected static $sizes = array('800x800', '400x400', '128x128', '64x64', '32x32', '16x16');

}
ProgramOperator.php
class ProgramOperator extends Model
{
use SoftDeletes;

public $timestamps = true;

protected $table = 'program_operators';

protected $fillable = array('name', 'is_active', 'mascot_name', 'color1_name', 'color2_name', 'color3_name', 'song_name', 'song_theme', 'song_lyrics');
public function entity()
{
return $this->morphTo();
}

public function image()
{
return $this->morphOne(ProgramLogo::class, 'imageable');
}

}
class ProgramOperator extends Model
{
use SoftDeletes;

public $timestamps = true;

protected $table = 'program_operators';

protected $fillable = array('name', 'is_active', 'mascot_name', 'color1_name', 'color2_name', 'color3_name', 'song_name', 'song_theme', 'song_lyrics');
public function entity()
{
return $this->morphTo();
}

public function image()
{
return $this->morphOne(ProgramLogo::class, 'imageable');
}

}
1 Reply
Dan Harrin
Dan Harrin2y ago
so what have you tried on the filament side? also maybe you should just go with something like spatie media library instead of your own models
Want results from more Discord servers?
Add your server