1

I am new in Laravel.

Now I want to use the middleware.

So Please help me.

My code is:

    $input = Input::except('_token');

    if(Auth::attempt($input)){         
        return redirect()->intended('dashboard');
    }else{
        return Redirect::to(route('login'))
                ->with('message','Sorry, Wrong Username and password .');
    }

The Auth::attempt is working perfectly and its redirecting to dashboard as expected.

But when I try to check the Auth::check function from the controller its returning the else statement.

public function dashboard(){      
    if(Auth::check()){
      return View::make('dashboard');
    }else{
      return "Not logged in";
    }
}

How can I fix the issue ?

Session.php

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
'http_only' => true,
Sruthi
  • 11
  • 4

2 Answers2

0

If you are using subdomain then change this line below (config/session)

'domain' => null,
to

'domain' => '.yourdomain.com',

Also if you are using files to store session

'driver' => env('SESSION_DRIVER', 'file'),

then check if you have write permission given to storage/framework/sessions directory . you also can try changing database sessions .

Mehul Kuriya
  • 608
  • 5
  • 18
0

use auth middleware on your route for which you are using below controller function

public function dashboard(){      
    if(Auth::check()){
      return View::make('dashboard');
    }else{
      return "Not logged in";
    }
}
Laravel User
  • 1,111
  • 1
  • 8
  • 24