[Suggestions] Checking authorization rights by "guard" instead of simple "roles"
I have two guard that shares the same controller.
Long story short: I need to identify rights by guards.
My thoughts currently are:
- Check if instance of
Foomodel. (Not sure if this is the best way) - To make it dynamic, make use of
config(first idea was set a key/value but...) - Remembered that
authconfig hasproviderwhich also has amodel
Now I could just write that down as a private method on my current controller but I have a feeling that I'll be using this more than once.
Where could I possible assign that method? In my Models by having a contract? But I have this feeling that I am violating SRP here.
I am also thinking if Auth class is the right one. Something like
Auth::method($request->user(), 'guardName') OR
Auth::method($request->user()) === config()
Looking for some opinions/suggestions. Anyone?
EDIT
Currently using while not yet decided
$user = $request->user();
$class_name = config('auth.providers.someProvider.model');
return $user instanceof $class_name;
Please or to participate in this conversation.