来自控制器的 Laravel 调用路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35744355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel call route from controller
提问by Umair Zahid
I am calling getting_started route after successfully login :
成功登录后我正在调用getting_started路由:
protected $redirectTo = '/getting_started';
Here is my getting_started route code :
这是我的 Getting_started 路线代码:
Route::get('/getting_started','UserController@getting_started');
And controller code :
和控制器代码:
public function getting_started()
{
$id= Auth::id();
$user = DB::table('user_profiles')->where('user_id', '=', $id)->first();
if($user->dashboard_access == 0)
{
DB::table('user_profiles')
->where('user_id', $id)
->update(['dashboard_access' => 1]);
return view('user.getting_started');
}
return view('user.dashboard');
}
It works perfectly and show in url :
它完美运行并显示在 url 中:
Now I actually want that if user.dashboard
view is call it show in url like :
现在我实际上希望如果user.dashboard
视图调用它显示在 url 中,例如:
And on getting_started
view show :
并在getting_started
视图显示:
It is possible to call dashboard route instead of :
可以调用仪表板路由而不是:
return view('user.dashboard');
My dashobard route is :
我的dashobard路线是:
Route::get('/dashboard',['middleware' => 'auth', function () {
return view('user.dashboard');
}]);
回答by Yasir Ijaz
What I understand it is that you are looking for is this function
我的理解是你正在寻找的是这个功能
return redirect()->route('dashboard');
return redirect()->route('dashboard');
It's my understanding of your question which can be wrong. Maybe you are asking something else.
我对你的问题的理解可能是错误的。也许你在问别的。
回答by Zakaria Acharki
That called Redirectionand especially you want to Returning A Redirect To A Named Route, you route called user.dashboard
so you could redirect to it using redirect()->route(route_name)
:
这称为重定向,尤其是您想要将重定向返回到命名路由,您路由被调用,user.dashboard
以便您可以使用redirect()->route(route_name)
以下命令重定向到它:
return redirect()->route('user.dashboard');
Hope this helps.
希望这可以帮助。