如你所知,我们可以发送数据,也可以通过重定向改变路由。重要的是,对于这样的类,我们如何定义操作顺序可更改的方法?
在这里呼唤:
return redirect(route_name);我希望重定向发生..。但是通过调用以下代码:
return redirect(route_name)-> with(key,value);redirect()必须做的操作更改,让方法接收数据,然后重定向。如果您只使用redirect(),它会立即重定向。我们如何为方法实现一种机制,使其操作发生变化?
发布于 2016-09-07 20:16:27
要使用参数重定向到指定的路由,可以这样做:
return redirect()->route('profile', ['id' => 1]);
摘自:https://laravel.com/docs/5.3/responses#redirecting-named-routes
供评论的最新情况:
如果您查看函数定义的helpers文件:
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php
您将看到,当您调用redirect时,它实际上总是从Laravel容器中获取一个实例。
if (! function_exists('redirect')) {
/**
* Get an instance of the redirector.
*
* @param string|null $to
* @param int $status
* @param array $headers
* @param bool $secure
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
*/
function redirect($to = null, $status = 302, $headers = [], $secure = null)
{
// If no path given return an instance from the container
if (is_null($to)) {
return app('redirect');
}
// Path given, call the 'to' method on an instance
return app('redirect')->to($to, $status, $headers, $secure);
}
}https://stackoverflow.com/questions/39378282
复制相似问题