Starting with Laravel 12, Laravel introduced the #[CurrentUser] attribute, making it easier to access the authenticated user inside controller methods. Instead of retrieving the user manually using Request object or auth() helper, you can now ask Laravel to inject the authenticated user directly into your method. This results in cleaner, more readable controller code while taking advantage of Laravel’s dependency injection system.

Here I want to give you and example:

Before Laravel 12, you would typically access the logged-in user like this in a controller

PHP
class ArticleController {
    public function store(StoreArticleRequest $request){
        # get current user
        $user = $request->user();
        // or
        $user = auth()->user();
        // ...
    }
}

But after laravel 12 you can inject the current user as dependency like this:

PHP
use App\Models\User;
use Illuminate\Container\Attributes\CurrentUser;
class ArticleController {
    public function store(StoreArticleRequest $request,#[CurrentUser] User $user){
       # the current user is $user
       // ...
    }
}

In the above example you can access current logged in user via $user, no need for request object or auth() helper.

# Why Use This Attribute?

Using #[CurrentUser] offers several advantages:

  • Cleaner controller methods
  • Less boilerplate code
  • No need to call $request->user()
  • Works naturally with Laravel’s dependency injection
  • Makes method dependencies more explicit

While the difference is small, these improvements add up across a large codebase and make controllers easier to read and maintain.