I am using laravel 5.4 as backend for my application and for front-end I am using angular. I am using laravel auth
for authentication.
Issue is Auth::attempt()
is working fine and if immediately I print the Auth::user()
then it prints the data but it returns false
if I try to fetch it in next method. But this functionality is working fine in hosted server.
Tested,
- Changing session from file to database.
- Changes in kernel.php (Content of $middleware).
- Did php artisan make:auth one more time.
- Did changes in user table column.
- Adding private $primarykey = 'id' to model.
- Adding 'web' middleware to all routes.
This is my Controller
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
public function login()
{
if (Auth::attempt(['email' => $email, 'password' => $password ]))
{
$response = array('response' =>'Succssfully Login!' , 'success' => true);
return $response;
}
}
This is where i am using Auth::check()
in the same controller
public function check()
{
if(Auth::check())
$response = array('response' =>'Authenticated' , 'success'=>true);
else
$response = array('response' =>'UnAuthenticated' , 'success'=>false);
return $response;
}
I am confused because same code is working fine in hosted server but not working on localhost. Do I need to do any http related changes in laravel for this?