Extendable models in Laravel

I'm trying to structure my models in such a way that there is always a baseUser with the basic functionality that every user needs.

And then in environment a) I might want tot extend this user in another way than in environment b).

My base class:

<?php
namespace App\Libraries;

use Illuminate\Database\Eloquent\Model;

abstract class basicUser extends model
{
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = array('name', 'email');

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('remember_token', 'password');

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $guarded = array();

    public function ratings()
    {
        return $this->hasMany('\App\Rating');
    }


    /*==========  Override class variable declarations for children.  ==========*/

    protected function setFillableAttribute($value)
    {
        if (count(class_parents($this)) > 1) # Check if there is more than one parent, they all need the Eloquent model.
        {
            # Yes, there are parents. We need to combine the parent $fillable with the extra ones in the child.
            $this->fillable = array_unique(array_merge($this->fillable,$value));
        }
        else
        {
            # No parents except Eloquent model.
            $this->fillable = $value;
        }
    }

    protected function setHiddenAttribute($value)
    {
        if (count(class_parents($this)) > 1) # Check if there is more than one parent, they all need the Eloquent model.
        {
            # Yes, there are parents. We need to combine the parent $hidden with the extra ones in the child.
            $this->hidden = array_unique(array_merge($this->hidden,$value));
        }
        else
        {
            # No parents except Eloquent model.
            $this->hidden = $value;
        }
    }

    protected function setGuardedAttribute($value)
    {
        if (count(class_parents($this)) > 1) # Check if there is more than one parent, they all need the Eloquent model.
        {
            # Yes, there are parents. We need to combine the parent $guarded with the extra ones in the child.
            $this->guarded = array_unique(array_merge($this->guarded,$value));
        }
        else
        {
            # No parents except Eloquent model.
            $this->guarded = $value;
        }
    }
}

The idea behind the set...Attribute() methods in my base class is that if a child wants to add to $fillable, $hidden or $guarded, the parent value isn't reset.

<?php
namespace App\Libraries;

use App\Libraries\basicUser;

class User extends  basicUser
{
    protected $fillable = array('extra');

    protected $hidden = array(); 

    protected $guarded = array();
}

Now what I'd really like is for my $u = user::find(1); to have password and remember_token to be hidden... but protected $hidden seems to be overridden.

Is this structure even possible? Am I approaching it in a wrong way?


ANSWERS:


$hidden is overwritten because you re-declare this attribute in child class. Remove the following from User class and it should be enough to make it work:

protected $hidden = array(); 


 MORE:


 ? Laravel 5 setting route parameter from middleware
 ? Using two different slugs on a route
 ? Don't change slug on update (In Laravel Model)
 ? Laravel Route model binding (slug) only works for show method?
 ? How to create slugs in Laravel
 ? django-autoslug not populating database
 ? How to create slugs in arabic characters in Django?
 ? Rails Friendly ID: slug is not generated on model.new or model.import
 ? Rails Friendly ID: slug is not generated on model.new or model.import
 ? Rails Friendly ID: slug is not generated on model.new or model.import