laravel backpack select2 placeholder

Viewed 496

How do I get dropdown list with placeholder saying "Select Category" as the default selection?

The following code did not render the placeholder

    $this->crud->addField([  // Select2
       'label'     => 'Category',
       'type'      => 'select2',
       'name'      => 'category_id', // the db column for the foreign key
       'entity'    => 'category', 
       'attribute' => 'name', 
       'attributes' => ['placeholder' => 'Select a category'],
       .... ])
2 Answers

add this in attributes:

'attributes' => [
   'data-placeholder' => 'Select Category'
 ]

Try just the

'placeholder' => 'Select Category',

without the 'attributes' => [...], that worked for me.

Related