Reputation: 1563
I am using Laravel spark, and I am restricting team access to models by employing a scope that is implemented in a trait
namespace App\Scopes;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class TeamScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->where('team_id', '=',Auth()->user()->currentTeam->id );
}
}
my issue is that when I run the DB seeder it fails because there is no user to auth against.
The seeder doesn't have any methods to allow me to log in a particular user.
is there a way to disable the global scope whilst seeding, or any other solution for that matter?
THanks
Upvotes: 0
Views: 757
Reputation: 1144
If you're calling the model inside the seed, you can just call ->withoutGlobalScopes()
first
more on that here https://laravel.com/docs/5.7/eloquent#query-scopes at the 'Removing Global Scopes' section.
Upvotes: 2