mostafamaklad / laravel-permission-mongodb

Associate users with roles and permissions using Laravel and MongoDB
https://maklad.dev
MIT License
112 stars 66 forks source link

assignRole not working in laravel 8 #123

Closed ovis-it closed 3 years ago

ovis-it commented 3 years ago

Hi, i got an error in a fresh installed laravel with mongodb. I use the seeder looks like so: `<?php namespace Database\Seeders; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Faker\Factory as Faker; use Illuminate\Support\Str; //use Spatie\Permission\Models\Role; use App\Models\User; use App\Models\RoleHierarchy; use Maklad\Permission\Models\Role; use Maklad\Permission\Models\Permission;

class UsersAndNotesSeeder extends Seeder { /**

`

if i run this seeder i get this error:

`Error

Call to a member function prepare() on null

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:331 327▕ // For select statements, we'll simply execute the query and return an array 328▕ // of the database result set. Each element in the array will be a single 329▕ // row from the database table, and will either be an array or objects. 330▕ $statement = $this->prepared( ➜ 331▕ $this->getPdoForSelect($useReadPdo)->prepare($query) 332▕ ); 333▕ 334▕ $this->bindValues($statement, $this->prepareBindings($bindings)); 335▕

  +13 vendor frames 

14 [internal]:0 App\Models\User::Maklad\Permission\Traits{closure}()

  +2 vendor frames 

17 database/seeders/UsersAndNotesSeeder.php:76 App\Models\User::assignRole()`

the mongodb driver is installed and it works. the admin user is insert in the collection user. ANY Ideas? THX THomas

mostafamaklad commented 3 years ago

Please make sure that the User Model is extending \Jenssegers\Mongodb\Eloquent\Model