I am using Laravel 5 that have a subdomain for each user profile. I have already the sessions
table in my database and this is my config/session.php
return [
'driver' => env('SESSION_DRIVER', 'database'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => true,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => '.stagedevelopment.dev',
'secure' => false,
'http_only' => true,
];
This is my routes.php
this will be called once the user is trying to login
Route::group(['domain' => '{account_alias}.'.stagedevelopment.dev'], function () {
Route::get('dashboard', 'DashController@index');
...
this is on the 'DashController@index'
on DashController.php
public function index(Request $request, $account_alias = null){
if ( Auth::user()){
// CODES TO CALL THE VIEW
}
}
In my sign-in in UserController
I modified it like this.
public function postSignIn( Request $request) {
$rules = array(
'email' => 'required|email',
'password' => 'required',
);
$validator = Validator::make( Input::all(), $rules );
if ( $validator->passes() ){
$remember = ( !is_null( $request->get('remember')) ? true : false );
if ( Auth::attempt( array( 'email' => $request->input('email'), 'password' => $request->input('password') ) ) ){
if ( Auth::check() ){
$account = \App\Account::where( 'alias', 'LIKE', Auth::user()->account->alias )->get();
if($account->count() > 0){
return Redirect::to('http://'. Auth::user()->account->alias.'http://.stagedevelopment.dev/app/dashboard');
}
}
}
}
}
My issue now is when I login a user, it won't authenticate by retrieving using Auth::check()
or Auth::user()
. But when I try to retrieve using $request->session()->get('uid')
it returns the user_id
of the user and it will return null when I call on Auth::logout()
.
question, did I missed something in my code? or if not, how can I put the $request->session()->get('uid')
into Auth::user() and Auth::check()
?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire