Replies: 3 comments
-
I did try your example, and i didn't get any exception
Maybe it is your implementation |
Beta Was this translation helpful? Give feedback.
-
@systemsolutionweb Yes, I looked more closely and found that only using dependency injection in the code does not give such an error. But if you use this namespace App\Console;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
public function __construct(
Application $app,
Dispatcher $events,
private \App\Services\Permission $permission;
}
} namespace App\Services\Permission;
class PermissionService
{
public function __construct(
private \Spatie\Permission\Models\Role $role,
) {
}
} |
Beta Was this translation helpful? Give feedback.
-
on kernel __construct configurations not loaded yet |
Beta Was this translation helpful? Give feedback.
-
If I want to adhere to the principle of dependency injection, and add
Spatie\Permission\Models\Role
to the __construct of any class, I will get an errorFatal error: Uncaught ReflectionException: Class "config" does not exist
Because the helper
config()
is not initialized yet at the moment.A simple example:
Now in the terminal, try typing a command, for example
php artisan cache:clear
, and you will get an error.I have a solution, I will offer it in PR ))
Versions
laravel/framework - v8.83.11
spatie/laravel-permission - 5.5.3
PHP 8.0.8
Windows 11
Beta Was this translation helpful? Give feedback.
All reactions