In Laravel 10, The Auth
facade provides various methods for authentication and user management, including accessing the currently authenticated user.
See the Below step to get data of logged in user.
Step 1 :Add Code in Your Controller File,
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function profile()
{
// Retrieve the currently authenticated user
$user = Auth::user();
// Access user data
$id = $user->id;
$name = $user->name;
$email = $user->email;
// Perform further actions with user data
return view('profile', compact('user'));
}
}
Step 2 :Add Code in Blade File
<p> User ID: {{ auth()->user()->id }} </p>
<p> User Name: {{ auth()->user()->name }} </p>
<p> User Email: {{ auth()->user()->email }} </p>
here, you can add users field name as per your requirement field, like first_name ,last_name , phone etc. Thank You