0
| 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 authorized (isAuthorized = 1).
But I have to make a permit for that one user do not have access to Controller 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 have access to Controller if you are authorized. You may not have access to Controller other’s user.
for example:
- If user_id => 1: may have access toControllerDadosCtrlandDados2Ctrl; if he accesses theDados3Ctrl, he won’t have access.
- If user_id => 2: may have access toControllerDados3Ctrl; if he accesses theDadosCtrlandDados2Ctrl, he won’t have access.
You are returning an error Trying to get property of non-object when using Auth::user->id en route.
Auth::id() is returning
null– Denali
Strange, you’re wearing the
$user = Auth::user();to receive the current user ?– teliz