I have installed a fresh laravel project with laravel spark. All running fine.
I then have installed Voyager with dummy data. All working until i login where i get an error. See screenshot
Steps to reproduce the behavior:
Allow you to log into the voyager admin

Does your user model extend Voyager's User model (TCG\Voyager\Models\User)?
If not, does it implement both the TCG\Voyager\Contracts\User Interface and TCG\Voyager\Traits\VoyagerUser trait?
One of these two must be true for Voyager to function.
@fletch3555 could you please hint how to do it?
Sparks App\User looks like
`
namespace App;
use Laravel\Spark\User as SparkUser;
class User extends SparkUser
{`
Or could you hint how to change the Voyager so that instead of using App/User it will use App/VoyagerUser
??
@gelinger777 my previous comment lists the things that are necessary. The easiest way to use Voyager is to have your User model extend Voyager's User model. But since PHP doesn't support multiple inheritance, we also provide an interface and trait that you can add to the model instead (it's all Voyager's User model adds anyway). Namespaces are in my previous comment, or you can check Voyager's User model source code to see what it does and mimic that
@fletch3555 I have made following
namespace App;
use Laravel\Spark\User as SparkUser;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\User as Authenticatable;
use TCG\Voyager\Contracts\User as UserContract;
use TCG\Voyager\Traits\VoyagerUser;
class User extends SparkUser
{
use VoyagerUser;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'authy_id',
'country_code',
'phone',
'two_factor_reset_code',
'card_brand',
'card_last_four',
'card_country',
'billing_address',
'billing_address_line_2',
'billing_city',
'billing_zip',
'billing_country',
'extra_billing_information',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'trial_ends_at' => 'datetime',
'uses_two_factor_auth' => 'boolean',
];
}
One second it worked somehow, and I could login to voyager, but on next login I am getting
Argument 1 passed to TCG\Voyager\Policies\MenuItemPolicy::checkPermission() must be an instance of TCG\Voyager\Contracts\User, instance of App\User given, called in /home/bln/Desktop/coinflora/vendor/tcg/voyager/src/Policies/BasePolicy.php on line 34 (View: /home/bln/Desktop/coinflora/vendor/tcg/voyager/resources/views/dashboard/sidebar.blade.php) (View: /home/bln/Desktop/coinflora/vendor/tcg/voyager/resources/views/dashboard/sidebar.blade.php) (View: /home/bln/Desktop/coinflora/vendor/tcg/voyager/resources/views/dashboard/sidebar.blade.php)
Could you be so kind to hint what should I change so it woks correctly?
You're missing the interface
@fletch3555 which one? I have copied the lines from your model...
implements UserContract ?
Yes that one
Yes, you are right. It has worked like that way. So in case somebody needs to join Spark together with Voyager, you would need to edit App/User model and make it look like
namespace App;
use Laravel\Spark\User as SparkUser;
use Carbon\Carbon;
use Illuminate\Foundation\Auth\User as Authenticatable;
use TCG\Voyager\Contracts\User as UserContract;
use TCG\Voyager\Traits\VoyagerUser;
class User extends SparkUser implements UserContract
{
use VoyagerUser;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'authy_id',
'country_code',
'phone',
'two_factor_reset_code',
'card_brand',
'card_last_four',
'card_country',
'billing_address',
'billing_address_line_2',
'billing_city',
'billing_zip',
'billing_country',
'extra_billing_information',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'trial_ends_at' => 'datetime',
'uses_two_factor_auth' => 'boolean',
];
}
I am not sure yet if it will be stable on both sides. Need to test.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
Yes, you are right. It has worked like that way. So in case somebody needs to join Spark together with Voyager, you would need to edit App/User model and make it look like
I am not sure yet if it will be stable on both sides. Need to test.