Automatically limit your models to the current team
So you're using spark, and you have teams enabled. You start creating models and want to have them be team specific. Instead of writing,
Model::where('team_id', auth()->user()->currentTeam->id)->get(); use this trait to add that behind the scenes so that every time you call on your model, it's assumed that you mean for the current team.
This assumes that the model has a
team_id, while it adds a scope of
where team_id = currentTeam->id.
Note: Implicit Route Model Binding in 5.2, auth session doesn't exist at the point of this trait causing issue. fixed in 5.3