geisi / jetstream-team-spatie-permission

12 stars 2 forks source link

Difference between Jetsteam roles and Spatie roles #1

Open C14r opened 2 years ago

C14r commented 2 years ago

Hey there,

first of all thank you very much for your great tutorial. I have a fresh Laravel installation with the changes from your tutorial. When visiting the team settings from my personal team everything works find, but if I'm viewing the team settings for another team (that I created) I get the following error:

Laravel\Jetstream\Jetstream::findRole(): Argument #1 ($key) must be of type string, null given, called in storage\framework\views\325c85d3b0d8d75b7d6747a756f8b79604092d3e.php on line 331 which is the file views/teams/team-member-manager.blade.php

Additionale: If I want to invite a user to a team, I only can select Administrator and Editor ... roles defined in JetstreamServiceProvider not the spatie roles.

Greating Christian

C14r commented 2 years ago

Hey,

I solved the first Problem. The DatabaseSeeder don't created the pivot attribute role. I changed the DatabaseSeeder from

$this->call([PermissionSeeder::class]);

User::factory(['email' => 'info@geisi.dev'])
    ->withPersonalTeam()
    ->hasAttached(Team::factory()->count(3))
    ->create();

to

$this->call([PermissionSeeder::class]);

$teams = Team::factory()->count(3)->create();

$user = User::factory([
    'email' => 'info@geisi.dev',
    'password' => bcrypt('password')
])
->withPersonalTeam()
->create();

$user->teams()->attach($teams, [
    'role' => 'admin'
]);

But how do I sync the Jetstream roles the the Spatie roles?

R00118189 commented 1 year ago

I also wonder if this approach makes sense. We have two different worlds here, spatie and Jetstream. I would say what Jetstream does is a hard-coded way of what the spatie package can do dynamically. The solution may be in the Jetstream service provider, where we can assign spatie roles with permissions, but this looks like hacking. I think the teams should be out of main Jetstream and used as a package, say Jetstream teams. Then, the implementation of roles could be rewritten to suit use cases.