Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alex32's avatar

Laravel 10 | why laravel doesn't see me as logged in?

The table session says I'm logged in, the lifetime in session.php is 120', and the Jetstream page says I'm logged in. But, none the lines below are able to retrieve $user, why? Thanks

$uid = Auth::id() ; // no static errors
$user = Auth::user(); // no static errors
$user = $request->user();   // no static errors
if (Auth::check()) {$user="logged!";}  // runtime: null
if (Auth::id()) {$user="logged!";}  // runtime: null
Log::info(var_dump($user));     // Debugbar runtime: null

0 likes
6 replies
tykus's avatar

Where is this code written?

alex32's avatar

@tykus It's in my AjaxController:


namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth; 
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;


class AjaxController extends Controller
{
      
    public function file_upload(Request $request)  {     
        
        $uid = Auth::id() ;  // user must be logged 
        $user = $request->user(); //$uid= user()->id;
        if (Auth::check()) {$user="logged!";}
		....
	
Snapey's avatar

Every request has a session. This is not an indication that you are logged in.

alex32's avatar
alex32
OP
Best Answer
Level 2

I think I found the problem. Auth::user() actually works, it's the Log that needs to be changed. Thanks everyone.

This doesn't work:

Log::info(var_dump($user));  

This works:

Log::info($user);  
kokoshneta's avatar

@alex32 var_dump outputs data, but returns void (nothing). So when you do Log::info(var_dump($user)), that outputs the user object in a string format to the browser, then it returns null. So your original log call is equivalent to Log::info(NULL).

Please or to participate in this conversation.