Laravel Sentinel referencing the wrong config file

有些话、适合烂在心里 提交于 2019-12-25 06:55:59

问题


So im using Cartalyst Sentinel to manage authentication and roles in Laravel 5.1. At first i downloaded the package and was adding additional query scopes and defining relations in the vendor/../EloquentUser class. Composer updated the package today and naturally all my code was removed. At which point i realized that i needed to have my own User class which extended EloquentUser and modify the published config file to use my own User class. However it seems that Sentinel is using the config file within the /vendor directory because when i modify that one to use my User model, it works, that is the query scopes and relations start to work on my users. But changing the published config has no effect on my application.

Im fairly new to Laravel and composer and all, coming from Codeigniter, so maybe i am doing something wrong or messed up while setting it up?


回答1:


There's steps for setup with Laravel here:

https://cartalyst.com/manual/sentinel/2.0#laravel-5

For Laravel 5.1 I've made a couple changes

Edit config/app.php:

$providers array

Cartalyst\Sentinel\Laravel\SentinelServiceProvider::class,

$aliases array

'Activation' => Cartalyst\Sentinel\Laravel\Facades\Activation::class,
'Reminder'   => Cartalyst\Sentinel\Laravel\Facades\Reminder::class,
'Sentinel'   => Cartalyst\Sentinel\Laravel\Facades\Sentinel::class,

Run this command to publish needed migrations and application config into your project folders

php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider"

I've documented how to extend the Eloquent User here

http://naomiaro.com/2015/07/08/multiple-login-attributes-with-sentinel-and-laravel/

use Cartalyst\Sentinel\Users\EloquentUser as SentinelUser;

class User extends SentinelUser {

}

Tell Sentinel which User model you're using in its published config file config/cartalyst.sentinel.php

'users' => [

    'model' => 'Namespace\User',

],



回答2:


Okay so i have been tinkering with Laravel for a while and gotten to know how it works better.

The mistake i had made was that i was including this statement on the top of my file (honestly Cartalyst's documentation had it so, i think its misleading for a newbee):

use Cartalyst\Sentinel\Native\Facades\Sentinel;

and then doing:

Sentinel::getUser();

So obviously it was referencing the config file in the vendor (Native) folder.

The correct way is to use the Sentinel Facade on the top:

use Sentinel;

and then it will reference the published configuration file.

I hope this helps any other newbee who makes the same mistake. :)



来源:https://stackoverflow.com/questions/31405749/laravel-sentinel-referencing-the-wrong-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!