Is there a tutorial or guide on this actions pattern in laravel we may consult?
What is your usual approach when you pass validated data into an action? Do you revalidate the data in the action or is there an implicit contract/assumption that the data is validated by the caller?
I prefer using DTO's solely for third party payloads/DTO's instead of for internal data transfering. However, argumentative; Spatie's Data package (spatie/laravel-data) has some cool features like transforming those DTO's to typescript 👀
Make it invokable so that it's $action($request->validated()); ? (without ->execute)
You can make it even cleaner:
public function store(CreateUserRequest $request, CreateUser $action): RedirectResponse
{
auth()->login(
$action->execute($request->validated())
);
return to_route('dashboard');
}
For readability I would rather use it has @nunomaduro did, I would use invokable instead of execute as someone else mentioned
Because of insufficient syntax highlighting, my code variant doesn't look very good, but with normal highlighting it is very easy to read.
I like the option suggested by @nunomaduro, but I don't like to create extra variables unnecessarily. I just don't see the point of it. But I agree with Nuno about invokable classes - I'm not a fan.
Invokable class doesn't say anything about typing and IDE can't tell you how to pass data correctly.