hEShaN hEShaN - 1 month ago 33
PHP Question

Trying to get property of non object laravel 5.3

I have two users Admin/Customer for the admin he needs to logged in to the system before accessing the services. My code works fine after login. But if i just type the url "../admin" in the browser then it will show the above error. I am a beginner to laravel. I need a way of informing the user to sign-in before accessing this page without showing this error. I didn't find any way to do it. Following is my routes.php file and the related route code. What do i have to change in this route.php file. Many thanks in advance

Route::group(['middleware' => 'App\Http\Middleware\Admin'], function()
{

Route::get('/admin/home', function()
{
// can only access this if type == A which is used to redirect to admin dashboard
return view('Admin/admin');
});
});

Answer

you can use the auth middleware to make sure your user is logged before checking for rights :

Route::group(['middleware' => ['auth','App\Http\Middleware\Admin']], function()
{

Route::get('/admin/home', function()
{
    // can only access this if type == A which is used to redirect to admin dashboard
    return view('Admin/admin');
});
});