Laravel 来自控制器的调用路由
Laravel call route from controller
登录成功后我正在调用getting_started路由:
protected $redirectTo = '/getting_started';
这是我的 getting_started 路线代码:
Route::get('/getting_started','UserController@getting_started');
和控制器代码:
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');
}
它完美运行并显示在 url 中:
现在我实际上想要如果 user.dashboard
视图被称为在 url 中显示,例如 :
并在 getting_started
上观看节目:
可以调用仪表板路由而不是:
return view('user.dashboard');
我的 dashobard 路线是:
Route::get('/dashboard',['middleware' => 'auth', function () {
return view('user.dashboard');
}]);
我的理解是你要找的是这个功能
return redirect()->route('dashboard');
我对你的问题的理解可能是错误的。也许你在问别的问题。
那叫 Redirection and especially you want to Returning A Redirect To A Named Route,你路由叫 user.dashboard
所以你可以使用 redirect()->route(route_name)
重定向到它:
return redirect()->route('user.dashboard');
希望对您有所帮助。
登录成功后我正在调用getting_started路由:
protected $redirectTo = '/getting_started';
这是我的 getting_started 路线代码:
Route::get('/getting_started','UserController@getting_started');
和控制器代码:
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');
}
它完美运行并显示在 url 中:
现在我实际上想要如果 user.dashboard
视图被称为在 url 中显示,例如 :
并在 getting_started
上观看节目:
可以调用仪表板路由而不是:
return view('user.dashboard');
我的 dashobard 路线是:
Route::get('/dashboard',['middleware' => 'auth', function () {
return view('user.dashboard');
}]);
我的理解是你要找的是这个功能
return redirect()->route('dashboard');
我对你的问题的理解可能是错误的。也许你在问别的问题。
那叫 Redirection and especially you want to Returning A Redirect To A Named Route,你路由叫 user.dashboard
所以你可以使用 redirect()->route(route_name)
重定向到它:
return redirect()->route('user.dashboard');
希望对您有所帮助。