In my application I have a User (duh)
class User {
public function teams()
{
return $this->belongsToMany(Team::class, 'team_user', 'user_id')->wherePivot('confirmed', '!=', null);
}
}
Im trying to make a model that extends the User, like so
class Teamleader extends User
{
protected $table = 'users';
public static function boot()
{
parent::boot();
static::addGlobalScope(new TeamleaderScope);
}
}
The idea is that a team leader is a user that has the isLeader boolean in the team_user pivot table set to true. In my TeamleaderScope I've
tried something like
class TeamleaderScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$model->teams()->wherePivot('isLeader', true);
}
}
but that seems to be wrong, cause Teamleader::all() just returns all the users. I've never tried extending a model like this, but it should be possible, right? Can anyone help me in the right direction?