Normally in the backpack crud controller we pass the column value like
$this->crud->addColumn([
'name' => 'name', // The db column name
'label' => "Username", // Table column heading
'type' => 'Text'
]);
$this->crud->addColumn([
'name' => 'age', // The db column name
'label' => "Age", // Table column heading
'type' => 'Number'
]);
and get the value in the backpack blade like
$crud->columns
output will come like
[
name: {name: "name", label: "Username", type: "Text", .....},
age: {name: "age", label: "Age", type: "Number", .....}
]
Above array index value are name, age. But i want it as 0, 1. How do i get index value as number?
As this is an array so we can use the PHP's array_values() function to re-index the array. like as follow.
array_values($crud->columns);
or in case of using this value in laravel blade js section then you can use as follow
{!! json_encode(array_values($crud->columns)) !!};
Ref. link:- https://www.php.net/manual/en/function.array-values.php