B
B
Baxer562017-10-04 00:06:47
Laravel
Baxer56, 2017-10-04 00:06:47

Why doesn't Laravel user remembering work?

Hello. I am doing a small educational project on Laravel. It was required to make non-standard authentication (based on a token, not a login \ password).
I sketched a little code for testing:

Routes

Route::get('/login',function(){
   Auth::login(User::findOrFail(1),true);
   echo('Login OK');

});

Route::get('/check_u',function(){

    dd(Auth::user());
});
Route::get('/logout',function (){
   Auth::logout();
});


Model User

<?php

namespace App;



use Illuminate\Notifications\Notifiable;

use Illuminate\Foundation\Auth\User as Authenticatable;

class  User extends Authenticatable
{
    use Notifiable;

    
    protected $user_id;
    protected $f_name;
    protected $l_name;
    protected $auth_token;


}


When going to /login, it says Login Ok, no errors, but when going to /check_u, it returns null.
That is, the user is simply not authenticated for unknown reasons.
But, what is most interesting - if you remove the line , then everything is fine, when you switch to check_u, the User instance is given. I googled all over, but I didn't find a solution. I hope for your help.echo('Login OK');
There is a user in the table
59d3fc36c42fc637132296.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-10-04
@Stalker_RED

if you remove the line echo('Login OK'); then everything is fine

And when you return echo, I bet there are errors headers already sent.
And you haven't looked at the session documentation yet.
Note:
To use cookie-based sessions, the session_start() function must be called before rendering anything to the browser .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question