-
app/Scopes/UserScope.php
Open in GitHubuse Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope; class UserScope implements Scope { public function apply(Builder $builder, Model $model) { if (auth()->check()) { $builder->where( 'user_id', session()->has('imposter_id') ? session()->get('imposter_id') : request()->user()->id ); } } }
-
app/Traits/BelongsToUser.php
Open in GitHubuse App\Scopes\UserScope; trait BelongsToUser { public static function bootBelongsToUser() { static::addGlobalScope(new UserScope()); } }
-
app/Models/Url.php
Open in GitHubuse App\Traits\BelongsToUser; use Illuminate\Database\Eloquent\Model; class Url extends Model { use BelongsToUser; // }