Laravel User Laravel User - 1 year ago 60
PHP Question

What is the differnece between these two back() methods in laravel 5.2?

I have tried both the back methods but i don't know which one is better or what is the difference between them.

function foo(Request $request){

/*1st back method*/
return back();

/*2nd back method*/
return redirect()->back();


Answer Source

They're the exact same, back() is just an alias. I personally prefer the latter as it's more readable and self-explanatory, as I'm redirecting the user back.

if (! function_exists('back')) {
     * Create a new redirect response to the previous location.
     * @param  int    $status
     * @param  array  $headers
     * @return \Illuminate\Http\RedirectResponse
    function back($status = 302, $headers = [])
        return app('redirect')->back($status, $headers);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download