[英]Conditions In Routes.php Laravel
抱歉,我是Laravel新手。 我想使用laravel 5.2在Routes.php中使用條件。登錄用戶后,我想調用showExperience函數,否則重定向到登錄。
我的routes.php代碼
Route::get('/profile', function () {
if (Auth::check()) {
$url = action('ProfilesController@showExperience');
return redirect($url);
} else {
return Redirect::to('login');
}
});
這是我的ProfilesController.php
public function showExperience(){
$data = Experience::all();
return view('profile')->with('experienceData',$data);
}
您應該為此目的使用中間件
例如:
Route::get('/profile', ['middleware' => 'auth', 'uses' => 'YourController@index']);
然后,您可以轉到app/Http/Middleware/Authenticate.php
和app/Http/Middleware/RedirectIfAuthenticated.php
來更改默認重定向值
這是我的解決方案
Route::get('/profile',[
'uses' => 'ProfilesController@showExperience',
'as' => 'profile',
'middleware' => 'auth'
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.