ahmedsaoud31 / laravel-permission-to-vuejs

Laravel Permission Package To Use it in VueJs
87 stars 27 forks source link

Call to undefined method App\Models\User::getRoleNames() #8

Closed tylerlmn closed 2 years ago

tylerlmn commented 2 years ago

Hey,

I use Laravel 8.x and Vue 2.x and have this error after installing: Call to undefined method App\Models\User::getRoleNames() (View: /resources/views/layouts/default.blade.php)

Code, which causes the error: <script type="text/javascript"> window.Laravel = { csrfToken: "{{ csrf_token() }}", jsPermissions: {!! auth()->check()?auth()->user()->jsPermissions():0 !!} } </script>

Version of spatie: "spatie/laravel-permission": "^5.4"

Can anyone help me? Thanks!

Regards, Tyler

tylerlmn commented 2 years ago

My user model: `<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use LaravelAndVueJS\Traits\LaravelPermissionToVueJS;

class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable, LaravelPermissionToVueJS;

/**
 * The attributes that are mass assignable.
 *
 * @var string[]
 */
protected $fillable = [
    'name',
    'email',
    'password',
];

/**
 * The attributes that should be hidden for serialization.
 *
 * @var array
 */
protected $hidden = [
    'password',
    'remember_token',
];

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',
];

}`

tylerlmn commented 2 years ago

Fixed, I have forgotten to add use Spatie\Permission\Traits\HasRoles;