简体   繁体   中英

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();

}

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM