Generally speaking, do you usually pass all request parameters to methods or just the ones required?
Example:
In my UserController i have:
public function store(StoreUserRequest $request, StoreUser $action): RedirectResponse
{
$action->handle($request->validated());
return redirect(route('dashboard', absolute: false));
}
The action called looks like this:
public function handle(array $attributes): void
{
// Store the new user
$user = User::create([
'first_name' => $attributes['first_name'],
'last_name' => $attributes['last_name'],
'email' => $attributes['email'],
'password' => Hash::make($attributes['password'])
]);
// Fire event to send verification mail
event(new Registered($user));
// Login the user
Auth::login($user);
}
So i basically pass all attributes of the request eventhough that might be to much.
This makes it a bit more flexible when adding attributes to the user model (which isn't that rare), but on the other hand, it adds some overhead and doesn't feel strict enough. Additionally, one could argue that it doesn't adhere to the Single Responsibility Principle (SRP) as it is now the actions job to handle the "not required" attributes.
What do you all think about it?