0
我是Laravel的新手,想知道會發生什麼;是防止用戶編輯彼此數據的最佳做法。防止其他用戶查看/編輯對方數據的最佳做法
我知道我可以使用過濾器和身份驗證來處理用戶頁面,例如。
Route::filter('auth', function($route)
{
$id = $route->getParameter('id');
if(Auth::check() && Auth::user()->id != $id) {
return Redirect::route('forbidden');
}
});
但是我想知道關於關係的網頁(即/ user_profile/14,user_settings/22等)。我是否爲這些[一組]路線中的每一個定義了過濾器,並根據關係檢查ID?例如
Route::filter('auth.user_settings', function($route)
{
$id = $route->getParameter('id');
if(Auth::check() && Auth::user()->user_settings->id != $id) {
return Redirect::route('forbidden');
});
Route::filter('auth.user_profile', function($route)
{
$id = $route->getParameter('id');
if(Auth::check() && Auth::user()->profile->id != $id) {
return Redirect::route('forbidden');
});
...etc
還是有更好的方法來做到這一點?
我覺得非常愚蠢。在我的防守中,這是漫長的一天,不知道我在想什麼。羅。謝謝 –