Laravel Backpack Authentification | Create a CRUD admin panel for users

5/5 - (1 vote)

By default after installed Backpack, all users are considered admins.

If that’s not what you want in your application (you have both users and admins), please:

  • Change app/Http/Middleware/CheckIfAdmin.php, particularly checkIfUserIsAdmin($user), to make sure you only allow admins to access the admin panel;
  • Change app/Providers/RouteServiceProvider::HOME, which will send logged in (but not admin) users to /home, to something that works for your app;

Authentication

Backpack uses Laravel’s default App\User model.

This is part 3 of the series seo site manager in Laravel.

Create a CRUD administration panel for users

To create a CRUD administration panel for users, run

php artisan backpack:crud user

This command will create the “users” table and password_resets table.

Now will see the user area in the admin sidebar.
baclpack user area

or create your custom user table

1. Create the migration

php artisan make:migration create_users_table --table=users

2. Add add the columns you need for the “users” table

Below are the columns I added.

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->string('image', 255)->nullable();     
            $table->integer('is_admin')->default(false);                      
            $table->timestamps();    
        });
    }

3. Run the migration

Because the user table already exists in my database, after I added the new fields (image, is_admin) I will run the php artisan migrate:fresh command.

The migrate:fresh command will drop all tables from the database and then execute the migrate command: php artisan migrate.

What is rememberToken() in the “users” table?

Before getting started, make sure that your users (or equivalent) table contains a nullable, string remember_token column of 100 characters. This column will be used to store a token for “remember me” sessions being maintained by your application. This can be done by using $table->rememberToken(); in a migration.

Install Laravel-Backpack PermissionManager

If You need to have both users and admin, Install Laravel-Backpack PermissionManager package. It allows admins to easily add/edit/remove users, roles and permissions, using Laravel Backpack.
Admin interface for managing users, roles, permissions, using Backpack CRUD.

This package is just a user interface for spatie/laravel-permission. It will install it, and let you use its API in code.

Hello there!

I hope you find this post useful!

I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

subscribe youtube

1 thought on “Laravel Backpack Authentification | Create a CRUD admin panel for users”

  1. i want to separate widgets to another section (ex: i have table in col-6 and i want to add widgets card in col-6 of row) can or not ? and please help me to share. thank you

    Reply

Leave a Comment

WebPedia.net