laravel-permission: with or withCount with users relation shows an error.

with or withCount works with permissions relation but when you add users relation it shows an error.

And also when you do it on tinker it goes completely fine. Very strange

My code

$roles = QueryBuilder::for(Role::class)
            ->allowedSorts('name')
            ->withCount('users')
            ->withCount('permissions')
            ->where('name', '!=', 'owner')
            ->where('guard_name', 'web')
            ->where('user_id', $user->id)
            ->get(['name', 'id']);
        return inertia('roles/staff/Index', ['roles' => $roles]);

Error

Class name must be a valid object or a string

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Adding that blows everything up. I might try starting over… mostly just working on getting a good base together I can constantly reuse for projects that need custom programming.

PHP 7.4.16 All that looks exactly the way it was installed as default.