alchermd
10 months ago
561
5
General

Do you prefer helper functions over Facades/DI?

Posted 10 months ago by alchermd

To be precise, I'm talking about something like:

public function store(Request $request)
{
    $request->validate([/** ... */]);

    if (Auth::check()) {
        // ...
    }

    return view('foo.bar');
}

over something like:

public function store()
{
    request()->validate([/** ... */]);

    if (auth()->check()) {
        // ...
    }

    return view('foo.bar');
}

I used to think that the first one is more clear since Facades and/or injected dependencies are explicitly defined as parameters/imports. But lately I've been seeing that using helper functions results to more terse code, which kinda leads to lesser cognitive overhead when scanning a certain codebase.

What do you prefer?

Please sign in or create an account to participate in this conversation.