Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent

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);
    }
}
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

gresendesa gresendesa Joined 19 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.