Reputation: 2062
I'm new in using Laravel and Backpack. I want to create a blade file for a field in backpack. I want to know to what correspond $field['name']
in this code ?
@include('crud::fields.inc.wrapper_start')
<label>Address</label>
<input
type="text"
name="{{ $field['name'] }}[text_address]"
value="{{ old(square_brackets_to_dots($field['name'].'.text_address')) ?? $field['value']['text_address'] ?? $field['default']['text_address'] ?? '' }}"
@include('crud::fields.inc.attributes')
>
@include('crud::fields.inc.wrapper_end')
Upvotes: 0
Views: 790
Reputation: 6193
Whatever you pass as name
when you add the field will then be available as $field['name']
inside the field blade file. So if you do:
CRUD::addField([
'name' => 'title',
'type' => 'your_custom_type',
]);
// or the same thing using the fluent syntax
CRUD::field('title')->type('your_custom_type');
Then inside your resources/views/vendor/backpack/crud/fields/your_custom_type.blade.php
file you'll find that $field['name']
will be title
.
PRO TIP: Since most Backpack fields have one input, in default Backpack fields we try as much as possible to use the $field['name']
as the name
of the input. That way, it's easier to understand: the name
of the field will be the name of the input, which in turn will be saved as the name
of the model attribute your want to update in the database. You can use $field['name']
for whatever you want, but we recommend you use it for the input name too.
Upvotes: 2