Getting Started

If it's your first time using Backpack, we heavily recommend you follow the steps below:

You've already got a model, App\Models\User... all Laravel projects do. So let's create a page to administer users. We want the admin to Create, Read, Update and Delete them. In Backpack, we call that a CRUD. And you can easily generate one for an existing Eloquent model, by running:

php artisan backpack:crud user

Run that in your terminal and choose field when asked which validation type you'd like. You can now click on the new sidebar item (or here) and you'll be able to see the entries in the users table. Now... even though most generated CRUDs work out-of-the-box, they probably won't be exactly what you need. But that's where Backpack shines, in how easy it is to customize.

To dig a little deeper, let's make a few changes to the Users CRUD

1. When Listing, let's remove the "password" column - no point in showing the hash. To do that, go to UserCrudController::setupListOperation() and remove the line saying CRUD::column('password'); - easy-peasy, right?

2. On Create & Update, let's add validation to forms. There are multiple ways to add validation but we've already chosen the simplest, validation using field attributes. Let's go to setupCreateOperation() and specify our validation rules directly on the fields:


                    CRUD::field('name')->validationRules('required|min:5');
                    CRUD::field('email')->validationRules('required|email|unique:users,email');
                    CRUD::field('password')->validationRules('required');
                  

3. On Create, let's hash the password. Currently, if we create a new User, it'll work. But if you look in the database... you'll notice the password is stored in plain text. We don't want that - we want it hashed. There are multiple ways to achieve this too. Let's use Model Events inside setupCreateOperation(). Here's how our method could look, when we also tap into the creating event, to hash the password:


                  protected function setupCreateOperation()
                  {
                      CRUD::field('name')->validationRules('required|min:5');
                      CRUD::field('email')->validationRules('required|email|unique:users,email');
                      CRUD::field('password')->validationRules('required');

                      \App\Models\User::creating(function ($entry) {
                          $entry->password = \Hash::make($entry->password);
                      });
                  }
                

4. On Update, let's not require the password. It should only be needed if an admin wants to change it, right? That means the validation rules will be different for "password". But then again... the rules will also be different for "email" (because on Update, we need to pass the ID to the unique rule in Laravel). Since 2/3 rules are different, let's just delete what was inside setupUpdateOperation() and code it from scratch:


                  protected function setupUpdateOperation()
                  {
                      CRUD::field('name')->validationRules('required|min:5');
                      CRUD::field('email')->validationRules('required|email|unique:users,email,'.CRUD::getCurrentEntryId());
                      CRUD::field('password')->hint('Type a password to change it.');

                      \App\Models\User::updating(function ($entry) {
                          if (request('password') == null) {
                              $entry->password = $entry->getOriginal('password');
                          } else {
                              $entry->password = \Hash::make(request('password'));
                          }
                      });
                  }
                

That's it. You have a working Users CRUD. Plus, you've already learned some advanced techniques, like using Model events inside CrudController. Of course, this only scratches the surface of what Backpack can do. To really understand how it works, and how you can best use Backpack's features, we heavily recommend you move on to the next step, and learn the basics.

So you've created your first CRUD? Excellent. Now it's time to understand how it works and what else you can do. Time to learn the basics - how to build and customize admin panels using Backpack. Please follow one of the courses below, depending on how you prefer to learn:

If you decide to use Backpack, please create a Backpack account and stay subscribed to the Security Newsletter (1-2 emails per year). That way, we can let you know if your admin panel becomes vulnerable in any way.

Of course, if you like our free & open-source core, you might also enjoy our premium add-ons:

  • PRO - adds 28 fields, 10 filters, 6 columns, 5 operations, 1 widget
  • DevTools - easily generate Laravel migrations and models, from a web interface
  • FigmaTemplate - create designs and mockups that are easy to implement in Backpack
  • EditableColumns - let your admins make quick edits, right from the table view
Go to your config/backpack/ui.php and change show_getting_started to false.

* this card is only visible on localhost. Follow the last step to hide it from localhost too.

@push('after_styles') @basset('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/base16/dracula.min.css') @endpush @push('after_scripts') @basset('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js') @endpush