I'm currently trying to implement a simple method on my User model:
public function becomeAMerchant()
{
return $this->assignRole('merchant');
}
However, whenever I call Auth::user() (or auth()->user()) on my MerchantController, I am unable to access this method (or any methods on the User model for that matter).
Specifically PHPStorm is telling me:
Method 'becomeAMerchant' not found on Illuminate\Contracts\Auth\Authenticatable|null
Here's my full User model:
<?php
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use Notifiable, SoftDeletes, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function itineraries()
{
return $this->hasMany(Itinerary::class);
}
public function becomeAMerchant()
{
return $this->assignRole('merchant');
}
public function isMerchant()
{
return $this->hasRole('merchant');
}
}
As a quick background, I'm using Spatie's laravel-permission package to manage roles and permissions thus far.
Can anyone help me figure out why I'm unable to access the methods on my User model?