You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The getPermissions() method in GateRegistrar.php returns an array instead of an Illuminate\Support\Collection as expected, causing a TypeError in Laravel 11.
Code snippet of problem
The error occurs in the vendor/yajra/laravel-acl/src/GateRegistrar.php file:
This method returns an array in the catch block, which causes a TypeError when a Collection is expected.
The error in my CLI:
TypeError
Yajra\Acl\GateRegistrar::getPermissions(): Return value must be of type Illuminate\Support\Collection, array returned
at vendor/yajra/laravel-acl/src/GateRegistrar.php:61
57▕ if (config('acl.cache.enabled', true)) {
58▕ // @phpstan-ignore-next-line
59▕ return $this->cache->rememberForever($key, function () {
60▕ return $this->getPermissionClass()->with('roles')->get();
➜ 61▕ });
62▕ } else {
63▕ return $this->getPermissionClass()->with('roles')->get();
64▕ }
65▕ } catch (Exception $exception) {
�[2m+9 vendor frames �[22m
10 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Yajra\Acl\AclServiceProvider))
�[2m+5 vendor frames �[22m
16 artisan:35
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
System details
Operating System: Debian GNU/Linux 12 (bookworm)
PHP Version: 8.2
Laravel Version: 11.0
Laravel-ACL Version: 11.1
Possible Solution
To resolve this issue, I downgraded to the more stable version of Laravel 10 and modified the getPermissions method to ensure it always returns a collection of Permission instances. The function has been simplified to avoid using else and uses a ternary operator for cleaner and more concise code.
If you're following the package's code standards, I can open a PR to implement the solution. Waiting for feedback.
Summary of problem or feature request
The
getPermissions()
method inGateRegistrar.php
returns an array instead of anIlluminate\Support\Collection
as expected, causing a TypeError in Laravel 11.Code snippet of problem
The error occurs in the
vendor/yajra/laravel-acl/src/GateRegistrar.php
file:This method returns an array in the catch block, which causes a TypeError when a Collection is expected.
The error in my CLI:
System details
Possible Solution
To resolve this issue, I downgraded to the more stable version of Laravel 10 and modified the getPermissions method to ensure it always returns a collection of Permission instances. The function has been simplified to avoid using else and uses a ternary operator for cleaner and more concise code.
If you're following the package's code standards, I can open a PR to implement the solution. Waiting for feedback.
The text was updated successfully, but these errors were encountered: