Hi. Nice to be here.
I have two classes. Profile and Student.
Student extends Profile. There are others classes that extend Profile in order to get shared attributes and methods. So, nothing tricky at that point.
Well, I want to inject some common elements into $fillable array attribute on every class that extends Profile. I mean, if Student has:
protected $fillable = ['foo'];
I want to inject 'bar' and 'baz' elements in order to get:
protected $fillable = ['bar', 'baz', 'foo'];
I need a way to change this attribute using the Profile constructor (or something similar). I've tried this but it seems Laravel just accepts the previous state of $fillable:
abstract class Profile extends Model
{
public function __construct(array $attributes = []){
$fillable = [
'bar', 'baz'
];
$this->fillable = array_merge($fillable, $this->fillable);
Model::__construct($attributes);
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community