Backpack for Laravel

Backpack for Laravel

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

Documentation    Support

Column Types

array

Enumerate an array stored in the db column as JSON.

[
   'name' => 'options', // The db column name
   'label' => "Options", // Table column heading
   'type' => 'array'
],

array_count

Count the items in an array stored in the db column as JSON.

[
   'name' => 'options', // The db column name
   'label' => "Options", // Table column heading
   'type' => 'array_count'
],

boolean

Show Yes/No (or custom text) instead of 1/0.

[
    'label' => 'Status',
    'type' => 'boolean',
    // optionally override the Yes/No texts
    // 'options' => [0 => 'Active', 1 => 'Inactive']
]

check

Show a favicon with a checked or unchecked box, depending on the given boolean.

[
   'name' => 'featured', // The db column name
   'label' => "Featured", // Table column heading
   'type' => 'check'
],

multidimensional_array

Enumerate the values in a multidimensional array, stored in the db as JSON.

[
   'name' => 'options', // The db column name
   'label' => "Options", // Table column heading
   'type' => 'multidimensional_array',
   'visible_key' => 'name' // The key to the attribute you would like shown in the enumeration
],

radio

Show a pretty text instead of the database value, according to an associative array. Usually used as a column for the "radio" field type.

[
    'name'        => 'status',
    'label'       => 'Status',
    'type'        => 'radio',
    'options'     => [
                        0 => "Draft",
                        1 => "Published"
                    ]
]

This example will show:

  • "Draft" when the value stored in the db is 0;
  • "Published" when the value stored in the db is 1;

text

The text column will just output the text value of a db column (or model attribute). Its definition is:

[
   'name' => 'name', // The db column name
   'label' => "Tag Name" // Table column heading
],

select

The select column will output its connected entity. Its name and definition is the same as for the select field type:

[
   // 1-n relationship
   'label' => "Parent", // Table column heading
   'type' => "select",
   'name' => 'parent_id', // the column that contains the ID of that connected entity;
   'entity' => 'parent', // the method that defines the relationship in your Model
   'attribute' => "name", // foreign key attribute that is shown to user
   'model' => "App\Models\Category", // foreign key model
],

select_multiple

The select_multiple column will output a comma separated list of its connected entities. Its name and definition is the same as the select_multiple field:

[
   // n-n relationship (with pivot table)
   'label' => "Tags", // Table column heading
   'type' => "select_multiple",
   'name' => 'tags', // the method that defines the relationship in your Model
   'entity' => 'tags', // the method that defines the relationship in your Model
   'attribute' => "name", // foreign key attribute that is shown to user
   'model' => "App\Models\Tag", // foreign key model
],

video

Display a small screenshot for a Youtube or Vimeo video, stored in the database as JSON using the "video" field type.

[
   'name' => 'name', // The db column name
   'label' => "Tag Name", // Table column heading
   'type' => 'video',
],

model_function

The model_function column will output a function on your main model. Its definition is:

[
   // run a function on the CRUD model and show its return value
   'label' => "URL", // Table column heading
   'type' => "model_function",
   'function_name' => 'getSlugWithLink', // the method in your Model
],

For this example, if your model would feature this method, it would return the link to that entity:

public function getSlugWithLink() {
        return '<a href="'.url($this->slug).'" target="_blank">'.$this->slug.'</a>';
    }

model_function_attribute

If the function you're trying to use returns an object, not a string, you can use the model_function_attribute column, which will output the attribute on the function result. Its definition is:

[
   'label' => "URL", // Table column heading
   'type' => "model_function_attribute",
   'function_name' => 'getSlugWithLink', // the method in your Model
   'attribute' => 'route'
],

ROLL YOUR OWN

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.

For example, here's how the text.blade.php file looks like:

{{-- regular object attribute --}}
<td>{{ str_limit(strip_tags($entry->{$column['name']}), 80, "[...]") }}</td>

The most useful variables you'll have in this file here are:

  • $entry - the database entry you're showing (Eloquent object);
  • $crud - all the crudpanel settings, options and variables;

Column Types