Geoff
Geoff

Reputation: 6629

How to fix Laravel's routing error with HttpException?

Am using zizaco entruest rbac and these are my web routes causing error

Route::group(['prefix' => 'user-management', 'middleware' => ['permission:admin']], function() {

    Route::get('/users', function(){
        return "sds";
    });

});

When i try navigating to

http://localhost:8000/user-management/users

am getting an error

Symfony \ Component \ HttpKernel \ Exception \ HttpException
No message

Where could i be wrong

I have commented all other routes and found this to be the culprit

I have setup my rbac as explained

https://github.com/Zizaco/entrust

Upvotes: 9

Views: 10411

Answers (5)

Zulfiqar Tariq
Zulfiqar Tariq

Reputation: 394

apparently your code looks fine. I guess you are having some problem in your middleware its not allowing you to pass through. you have used permission:admin so i guess you should log in as admin and then it will be working fine.

Upvotes: 0

Cong Chen
Cong Chen

Reputation: 2436

You should create a 403.blade.php template view under resources/views/errors directory.
Your application's exception handler do not find the exception status code associated view, so it return the exception directly.

Upvotes: 8

Basheer Kharoti
Basheer Kharoti

Reputation: 4292

You need to put auth middleware as well as it checks permission for an auth user within permission middleware. You can fix it by just putting auth middleware and then try logging in, now you can navigate to users url.

 Route::group(['prefix' => 'user-management', 'middleware' => ['auth', 'permission:admin']], function() {

    Route::get('/users', function(){
       return "sds";
    });

 });

Upvotes: 5

Mark Walet
Mark Walet

Reputation: 1186

I've looked up the middleware. It says the following:

if ($this->auth->guest() || !$request->user()->can($permissions)) {
    abort(403);
}

This means that it crashes without a message if you aren't authenticated or you cannot do something because you don't have permission.

You could try to dd() something in here before the abort. Just to see if it reaches this. If it does check this page in the Laravel documentation about abort() and custom error pages: https://laravel.com/docs/5.5/errors#http-exceptions

Upvotes: 0

E. S.
E. S.

Reputation: 2919

To help you with this we need more information.

  • Is this the only route in your application?
  • Did you authenticate the user before trying to access /user-manag... ?
  • What's inside your app/Http/Kernel.php file? Did you add permission middleware?

Not sure what kind of http code are you receiving (is it a 403? or a 500?).

Things you can do that might help:

  1. Enable debug mode (change your .env (or config/app.php) DEBUG to "true")
  2. Check your laravel.log file (storage/logs/laravel.log)
  3. Install laravel-debugbar. This package can give you better insight about what's happening in your app. https://github.com/barryvdh/laravel-debugbar

Upvotes: 0

Related Questions