Closed scottybo closed 6 years ago
I don't have any experience with Spark, so you'll have to figure that out yourself.
Fair enough!
So far so good on Spark, however.. When trying to use $user->is('admin')
I get the error:
Type error: Argument 1 passed to Illuminate\Database\Eloquent\Model::is() m
ust be an instance of Illuminate\Database\Eloquent\Model, string given, cal
led in /var/www/html/holly-spark/app/Console/Commands/SetUsersAssignedRole.
php on line 81
Everything works fine if I use Bouncer::is($user)->a('admin')
My User Model looks like this:
namespace App;
use Laravel\Spark\CanJoinTeams;
use Laravel\Spark\User as SparkUser;
use Silber\Bouncer\Database\HasRolesAndAbilities;
use Config;
class User extends SparkUser
{
use CanJoinTeams, HasRolesAndAbilities;
It would be nice to use the shorter $user->is()
command - any ideas?
The docs show how to do this:
$user->isAn('admin');
BTW, I would strongly advise against checking the user's role directly. As outlined in the docs:
Note: Generally speaking, you should not have a need to check roles directly. It is better to allow a role certain abilities, then check for those abilities instead. If what you need is very general, you can create very broad abilities. For example, an
access-dashboard
ability is always better than checking foradmin
oreditor
roles directly. For the rare occasion that you do want to check a role, that functionality is available here.
@JosephSilber thanks - this is a special case (we're checking for a superadmin - i.e. me!)
@scottybo is that a question?
Does this package work in conjunction with Laravel Spark? If so, are there any 'gotchas' or special steps required?