Back

clean as fuck.

image

6

780

  • No matching results...
  • Searching...

/ 1000

Is there a tutorial or guide on this actions pattern in laravel we may consult?

83

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?

85

i prefer passing DTO to execute

1

127

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 👀

80

Make it invokable so that it's $action($request->validated()); ? (without ->execute)

1

114

You can make it even cleaner:

public function store(CreateUserRequest $request, CreateUser $action): RedirectResponse
{
auth()->login(
$action->execute($request->validated())
);

return to_route('dashboard');
}

1

31

For readability I would rather use it has @nunomaduro did, I would use invokable instead of execute as someone else mentioned

1

87

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.

70