sentinel
sentinel copied to clipboard
Laravel 6 and Sentinel 3 Installation
Hi Guys,
I'm kinda stuck installing Sentinel in my fresh Laravel 6 project. When I install this in my last Laravel 5.8 project and Sentinel 2 no problems encountered.
Your Environment
- OS and Version: Windows 10 Pro 64bit
- PHP Version: 7.2
- Sentinel Version: 3
Expected behaviour
I follow the installation process in Cartalyst/Sentinel
Actual behaviour
When running composer require cartalyst/sentinel "^3.0" an error has occur.
[2019-12-03 09:42:44] local.ERROR: Argument 1 passed to Cartalyst\Sentinel\Activations\IlluminateActivationRepository::__construct() must be of the type string, null given, called in C:\laragon\www\pse\vendor\cartalyst\sentinel\src\Laravel\SentinelServiceProvider.php on line 243 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Argument 1 passed to Cartalyst\Sentinel\Activations\IlluminateActivationRepository::__construct() must be of the type string, null given, called in C:\laragon\www\pse\vendor\cartalyst\sentinel\src\Laravel\SentinelServiceProvider.php on line 243 at C:\laragon\www\pse\vendor\cartalyst\sentinel\src\Activations\IlluminateActivationRepository.php:54)
[stacktrace]
#0 C:\laragon\www\pse\vendor\cartalyst\sentinel\src\Laravel\SentinelServiceProvider.php(243): Cartalyst\Sentinel\Activations\IlluminateActivationRepository->__construct(NULL, NULL)
#1 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\Container.php(800): Cartalyst\Sentinel\Laravel\SentinelServiceProvider->Cartalyst\Sentinel\Laravel\{closure}(Object(Illuminate\Foundation\Application), Array)
#2 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\Container.php(682): Illuminate\Container\Container->build(Object(Closure))
#3 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\Container.php(630): Illuminate\Container\Container->resolve('sentinel.activa...', Array)
#4 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(768): Illuminate\Container\Container->make('sentinel.activa...', Array)
#5 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\Container.php(1246): Illuminate\Foundation\Application->make('sentinel.activa...')
#6 C:\laragon\www\pse\vendor\cartalyst\sentinel\src\Laravel\SentinelServiceProvider.php(394): Illuminate\Container\Container->offsetGet('sentinel.activa...')
#7 C:\laragon\www\pse\vendor\cartalyst\sentinel\src\Laravel\SentinelServiceProvider.php(48): Cartalyst\Sentinel\Laravel\SentinelServiceProvider->garbageCollect()
#8 [internal function]: Cartalyst\Sentinel\Laravel\SentinelServiceProvider->boot()
#9 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(32): call_user_func_array(Array, Array)
#10 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#11 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#12 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Container\Container.php(591): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#13 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(828): Illuminate\Container\Container->call(Array)
#14 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(811): Illuminate\Foundation\Application->bootProvider(Object(Cartalyst\Sentinel\Laravel\SentinelServiceProvider))
#15 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(Cartalyst\Sentinel\Laravel\SentinelServiceProvider), 14)
#16 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(812): array_walk(Array, Object(Closure))
#17 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\BootProviders.php(17): Illuminate\Foundation\Application->boot()
#18 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(211): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#19 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array)
#20 C:\laragon\www\pse\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()
#21 C:\laragon\www\pse\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 {main}
"}
Steps to reproduce
Running command composer require cartalyst/sentinel "^3.0"
Thank you in advance,
@nejimz Does this happen only when you run the composer require
or after the dependency is installed?
I don't have a Windows machine to test at the moment, but on Mac, kinda the same PHP version, i haven't detected any problem :, but seems that Laravel can't read or parse the Sentinel config file properly.
@brunogaspar it happen when I run composer require. Thank you for response.
Don't have any idea to fix this but currently I created another project that using laravel 5.8 and using sentinel 2 so that I can move on to my project.
This is a cache + permissions issue, what I do was remove the sentinel package, then change the permissions (chmod 777 -R in my case), then composer dump-auto && php artisan clear-compiled && php artisan config:cache, and then install again the sentinel package, work like a charm
I hope can help
@salamand3r thank you for giving time on giving information. I'll give update once I try this steps but currently I'm using windows.
Thank you,
I too have the issue when installing sentinel 3.0 with laravel 6.0. I tried following commands still not works
- composer dump-autoload
- php artisan clear-compiled
- php artisan config:cache
@meekahCodes I had the same error as you, I went into my .yaml file and specifiied php version 7.2 for my project and that fixed it for me.
** PROBLEM NOT SOLVED ***
I get this error in Laravel 7. Help please.
Argument 1 passed to Cartalyst\Sentinel\Activations\IlluminateActivationRepository::__construct() must be of the type string, null given, called in /home/vagrant/ego/vendor/cartalyst/sentinel/src/Laravel/SentinelServiceProvider.php on line 243
Unfortunatly I don't have the time to rewrite the code and change this but here is a quick fix which worked for me:
Open up SentinelServiceProvider.php
Open up ServiceProvider.php (The class extended in SentinelServiceProvider)
Change this:
protected function mergeConfigFrom($path, $key)
{
if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) {
$this->app['config']->set($key, array_merge(
require $path, $this->app['config']->get($key, [])
));
}
}
To this:
protected function mergeConfigFrom($path, $key)
{
$this->app['config']->set($key, array_merge(
require $path, $this->app['config']->get($key, [])
));
}
Just run the command again and it should work now.
php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider"
Don't forget to reset this code change afterwards!
Basically you just remove the if statement temporary because that statement evaluates to false, which is why the config is never set.
Hope it helps!
Ok, so this issue will hunt you down at runtime too. So the only "quick" solution would be to remove that if statement. I might look into this further tonight
EDIT: It's still a hack but I removed the if-statement temporary and executed php artisan config:cache
After that, I undid the change and it worked.
So what you could do is, before you install Sentinel, cache your configuration and install it afterwards. Let me know if it worked for you guys
This problem also happened to me when installing on laravel 8, if it gives the composer dump-autoload issue when installing the sentienl, what i did that go to cartalyst/sentinel/src/Laravel/SentinelServiceProvider and apply the one conditions anywhere where the issue.
Apply below steps
- if(!empty($config))
- php artisan optimize
- php artisan vendor:publish This piece of code gives me error so i fixed that with: apply the first step anywhere if it gives error, the example is given below.
protected function setOverrides() { $config = $this->app['config']->get('cartalyst.sentinel'); if(!empty($config)){ $users = $config['users']['model'];
$roles = $config['roles']['model'];
$persistences = $config['persistences']['model'];
if (class_exists($users)) {
if (method_exists($users, 'setRolesModel')) {
forward_static_call_array([$users, 'setRolesModel'], [$roles]);
}
if (method_exists($users, 'setPersistencesModel')) {
forward_static_call_array([$users, 'setPersistencesModel'], [$persistences]);
}
if (method_exists($users, 'setPermissionsClass')) {
forward_static_call_array([$users, 'setPermissionsClass'], [$config['permissions']['class']]);
}
}
if (class_exists($roles) && method_exists($roles, 'setUsersModel')) {
forward_static_call_array([$roles, 'setUsersModel'], [$users]);
}
if (class_exists($persistences) && method_exists($persistences, 'setUsersModel')) {
forward_static_call_array([$persistences, 'setUsersModel'], [$users]);
}
}
}
Unfortunatly I don't have the time to rewrite the code and change this but here is a quick fix which worked for me:
Open up SentinelServiceProvider.php
Open up ServiceProvider.php (The class extended in SentinelServiceProvider)
Change this:
protected function mergeConfigFrom($path, $key) { if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) { $this->app['config']->set($key, array_merge( require $path, $this->app['config']->get($key, []) )); } }
To this:
protected function mergeConfigFrom($path, $key) { $this->app['config']->set($key, array_merge( require $path, $this->app['config']->get($key, []) )); }
Just run the command again and it should work now.
php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider"
Don't forget to reset this code change afterwards!
Basically you just remove the if statement temporary because that statement evaluates to false, which is why the config is never set.
Hope it helps!
Thank you so much , it's work for my when i change it like this ❤️