0
votes

We have several Laravel applications that use Backpack for the admin panel. A developer wrote a package that used Single sign-on. We have removed this package as it was not working correctly. Once Composer was used to updating Laravel and remove the package, there are NO routes to deal with admin login. Our applications use Laravel 5.8/6 and Backpack 3.6/4.0.

I created another test application with Laravel 5.8 using Backpack 3.6, and the routes are available for login. As you can see, all the login routes are available.

fresh install routes available

If you look at the following image, you can see the login routes are all missing.

removed SSO package no login routes available

Is there a way to add the routes in again? Laravel Backpack is still installed, but I need to re-register the routes.

All the settings in the application are set to default. I have even made the default authentication guard in config/auth.php to Backpack.

config/auth.php

'defaults' => [
    'guard' => 'backpack',
    'passwords' => 'users',
],
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],
],

config/backpack/base.php

'route_prefix' => 'admin',
'setup_auth_routes' => false,
'setup_dashboard_routes' => true,
'setup_my_account_routes' => true,
'user_model_fqn' => App\Models\BackpackUser::class,

'middleware_class' => [
    App\Http\Middleware\CheckIfAdmin::class,
    \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    // \Backpack\Base\app\Http\Middleware\UseBackpackAuthGuardInsteadOfDefaultAuthGuard::class,
],

// Alias for that middleware
'middleware_key' => 'admin',
'authentication_column'      => 'email',
'authentication_column_name' => 'Email',
'guard' => 'backpack',
'passwords' => 'backpack',

config/backpack/permissionmanager.php

'models' => [
    'user' => App\Models\BackpackUser::class,
    'permission' => Backpack\PermissionManager\app\Models\Permission::class,
    'role' => Backpack\PermissionManager\app\Models\Role::class,
],

'allow_permission_create' => false,
'allow_permission_update' => false,
'allow_permission_delete' => false,
'allow_role_create'       => true,
'allow_role_update'       => true,
'allow_role_delete'       => true,

'multiple_guards' => true,

app/Models/BackpackUser.php

class BackpackUser extends User
{
    use CrudTrait;
    use HasRoles;
    use InheritsRelationsFromParentModel;

    protected $table = 'users';
    
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordNotification($token));
    }
    
    public function getEmailForPasswordReset()
    {
        return $this->email;
    }
}

So pretty much standard settings. I cannot figure out why the routes are not registered and available. If you get to http://localhost/admin, I get redirected to http://localhost/admin/login, which gives a 404 error. Can anyone help?

1
I have already tried php artisan optimize:clear and also composer dump-autoload but the routes are not appearing. How do I register the routes again ? Add the routes from the backpack src to routes/base.php ? - codyCode

1 Answers

1
votes

You have to enable 'setup_auth_routes' => true in config/base.php. This will allow Backpack to use the standard routes. Then the second step is to use Auth::routes(); inside your routes/web.php

If you are missing some/all of the controllers or UIs then you can scaffold them:

  1. Install laravel/ui part using composer require laravel/ui
  2. Use php artisan ui vue --auth or php artisan ui bootstrap --auth or php artisan ui react --auth depending on what you use for the front-end.