| id | user_id | url_to | controller | isAuthorized |
| 1 | 1 | page1 | DadosCtrl | 1 |
| 2 | 2 | page3 | Dados3Ctrl | 1 |
| 3 | 1 | page2 | Dados2Ctrl | 1 |
I have a middleware that is only allowed to enter who is allowed (% with%).
But I have to make a permission for a isAuthorized = 1
not to have access to user
of the other
Route::group(['middleware' => ['auth', 'activated', 'pages.auth']], function(){
echo Auth::user()->id; // ERRO : Trying to get property of non-object
Route::get('pages', 'Pages\PagesController@index');
$pages = Pages::where('isAuthorized', true)->get();
//$pages = Pages::where('isAuthorized', true)->where('user_id', Auth::user()->id)->get();
// precisaria do Auth::user()->id, mas ocorre um erro
foreach($pages AS $p){
$s = $p->page;
Route::get($s->url_to.'/', "Pages\$s->controller@index");
Route::get($s->url_to.'/{id}', "Pages\$s->controller@show");
}
});
The user can only access the Controller
for his and if he is authorized. You will not be able to access Controller
of other Controller
.
for example:
- If
user
: can have access touser_id => 1
Controller
andDadosCtrl
; if it accessesDados2Ctrl
, it will not have access. - If
Dados3Ctrl
: may have access touser_id => 2
Controller
; if it accessesDados3Ctrl
andDadosCtrl
, it will not have access.
You are returning a Dados2Ctrl
error while using Trying to get property of non-object
on the route.