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.