Binding user ID in Laravel requests without the headache: Extend FormRequest, override prepareForValidation(), and merge the user()->id automatically. This way, no need to pass user_id in every request manually! 🎉
Back
•
In what cases would you prefer that over calling `auth()->user()` in the Controller?
•
In response to @bernhardk
My approach ensures cleaner controllers and allows for logic reuse across various parts of my API project at least from my perspective :D. It's perfect for consistently binding and validating the user ID.
For simpler cases where it's only needed in one place, I directly use auth()->user() within the controller.