Backpack for Laravel

Backpack for Laravel

A collection of Laravel packages to build a custom admin panel.

Documentation    Support

Basic Features

In a basic CRUD, you will only need to:

  • specify what fields the create/update form should show;
  • specify what columns the table view should show;

Fields

Fields are defined in the Controller and determine the way that particular field looks in the add / edit view.

Think of the fields as <input type=”text” /> but that does everything for you - triggers a datepicker, an upload button, validation, a 1-n relationship, an n-n relationship, etc.

Existing field types

For each of them, you only need to define it properly in the Controller's setup() method. Let's take an example field type, for a text input. You only need to define name, label and type, all field types also have the optional attributes below:

<?php

$this->crud->addField([
     // MANDATORY
    'name'  => 'address', // DB column name (will also be the name of the input)
    'label' => 'Street address', // the human-readable label for the input
    'type'  => 'text', // the field type (text, number, select, checkbox, etc)
    
     // OPTIONAL + example values
    'default'    => 'some value', // default value
    'hint'       => 'Some hint text', // helpful text, show up after input
    'attributes' => [
       'placeholder' => 'Some text when empty',
       'class' => 'form-control some-class'
     ], // extra HTML attributes and values your input might need
     'wrapperAttributes' => [
       'class' => 'form-group col-md-12'
     ] // extra HTML attributes for the field wrapper - mostly for resizing fields using the bootstrap column classes
]);

In addition:
If you don't specify the label, the CRUD will try to guess one for you, based on the name.
If you don't specify a field type, the CRUD will try to guess one for you, based on the name.

Check out the existing 44+ field types in the CRUD > Features > Fields section.

Custom field types (roll your own)

If you can't find the functionality you need in the existing field types, you can very very easily roll your own.

Columns

Columns represent the way your information is shown in the table view.

Since CRUD v2.1, columns are defined the same way fields are: each column type has its own blade file, which can be overwritten by placing a file with the same name in your resources\views\vendor\backpack\crud\columns.

All column types must have their name, label and type specified, but some could require some other attributes too.

<?php

$this->crud->addColumn([
         'name' => 'name', // The db column name
         'label' => "Tag Name", // Table column heading
  			 'type' => 'Text'
         ]);

Check out the 12+ column types in the CRUD > Features > Column Types section.

If you can't find the functionality you need in the existing column types, you can very very easily roll your own.

Callbacks

Developers coming from GroceryCRUD or other CRUD systems will be looking for callbacks to run before_insert, before_update, after_insert, after_update.

There are no callbacks in Backpack, because there's no need. The code for the insert&update operations is out in the open for you to customize. Notice your EntityCrudController already has the following methods, which you can modify as you wish:

  • you can copy-paste the logic in the package and modify it to fit your use case;
    or
  • you can do things before or after the logic is called;
		public function store(StoreRequest $request)
    {
        // <---------  here is where a before_insert callback logic would be
        $response = parent::storeCrud();
        // <---------  here is where a after_insert callback logic would be
        return $response;
    }

    public function update(UpdateRequest $request)
    {
        // <---------  here is where a before_update callback logic would be
        $response = parent::updateCrud();
        // <---------  here is where a after_update callback logic would be
         return $response;
    }

Please see this github issue for a rephrased explanation.

Basic Features