How to create a Laravel 5.4 session in a database

I looked through the documentation and I spent hours trying to figure it out, and this is really my last resort. If this does not work, I may have to get a subscription to Laracasts. I follow this guide and it does not seem to work for me. https://laravel.com/docs/5.4/session

I hope someone can help me and say what I'm doing wrong. When I execute my API request, I get a successful response and return the user from the database, but he does not create a session in the session table. Also, I am not getting any errors in laravel.log.

I can create a user without problems. I can match the hashed passwords when retrieving the user.

api.php

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('/users', 'UserApiController@login');

UserApiController.php

public function login()
{
    $input = Request::all();
    $user = new User();
    $response = ['success' => false];
    if (!$user->validate($input))
    {
        return response()->json($response, 412);
    }
    $user = User::where('Email', $input['Email'])->where('Password', User::makePassword($input['Password']))->first();

    Log::info($user); //returns the user object successfully

    if (!isset($user))
    {
        return response()->json($response, 401);
    }
    session('user', $input]);  //<--this is not working
    $response['success'] = true;
    return response()->json($response, 200);
}
+4
1

, , , , - api, . app/Http/Kernel.php, , web :

\Illuminate\Session\Middleware\StartSession::class,

api , , API , , (api_token ), , ,

+3

Source: https://habr.com/ru/post/1675464/


All Articles