When using back() in the Laravel this should be preceded by redirect()?

Asked

Viewed 80 times

3

Observing many implementations I saw that the staff uses with a certain frequency return redirect()->back()... My question is:

What’s the difference between return redirect()->back()... and return back()...

1 answer

3


These are two ways of doing the same thing, namely, redirect to the previous location and are functions that return the class instance Redirector and its main objective is to facilitate the development of.

Structures:

back()

function back($status = 302, $headers = [], $fallback = false)
{
    return app('redirect')->back($status, $headers, $fallback);
}

redirect()

function redirect($to = null, $status = 302, $headers = [], $secure = null)
{
    if (is_null($to)) {
        return app('redirect');
    }

    return app('redirect')->to($to, $status, $headers, $secure);
}

About the structures, is that the redirect can call the other methods while back() would already be the call of the method, the two forms are correct, but, the back() in this case it fits better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.