PHP code example of wisam-alhennawi / lara-forms-builder
1. Go to this page and download the library: Download wisam-alhennawi/lara-forms-builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wisam-alhennawi / lara-forms-builder example snippets
return [
'default_group_wrapper_class' => 'lfb-group-wrapper',
'default_field_wrapper_class' => 'lfb-field-wrapper',
'card_field_error_wrapper_classes' => 'shadow mb-4 overflow-hidden rounded-md col-span-2 sm:col-span-2',
'primary_button_classes' => 'lfb-primary-button',
'secondary_button_classes' => 'lfb-secondary-button',
'footer_buttons_wrapper_classes' => 'lfb-buttons-wrapper',
'previous_button_classes' => 'lfb-secondary-button',
'next_button_classes' => 'lfb-primary-button',
];
protected function fields(): array
{
return [
[
'fields' => [
'name' => [
'type' => 'input',
'label' => __('models/users.fields.name'),
],
'email' => [
'type' => 'input',
'label' => __('models/users.fields.email'),
'readOnly' => true
],
'role' => [
'type' => 'radio',
'label' => __('models/users.fields.role'),
'options' => [
'1' => __('Employee'),
'2' => __('Manager')
]
],
'status' => [
'type' => 'select',
'label' => __('models/users.fields.status'),
'options' => [
[
'value' => '1',
'label' => __('Pending')
],
[
'value' => '2',
'label' => __('Active')
],
[
'value' => '3',
'label' => __('Retired')
]
]
],
'last_update' => [
'type' => 'date-picker',
'label' => __('models/users.fields.last_update')
],
'remark' => [
'type' => 'textarea',
'label' => __('models/users.fields.remark'),
'field_wrapper_class' => 'col-span-2',
],
]
]
];
}
public function saveAttachment($attachmentValue) {
$attachmentValue->storeAs('attachments', $attachmentValue->getClientOriginalName());
}
public array $contactIdOptions = [];
public function getContactIdOptions($searchPickerTerm)
{
return Contact::select('id', 'name')
->where('name', 'like', '%' . $searchPickerTerm . '%')
->get()
->each(function($row){
$row->key = $row->id;
$row->value = $row->name;
$row->labels = collect(['White', 'Green', 'Blue', 'Red', 'Yellow'])->random(rand(0, 3))->toArray();
})
->toArray();
}
// will return ($contact_id_search_picker_selected_value) which used in blade to display the selected option
public function getContactIdSearchPickerSelectedValueProperty()
{
if ($this->contact_id) {
return Contact::find($this->contact_id)->name;
}
return null;
}
protected function fields(): array
{
return [
[
'fields' => [
'contact_id' => [
'type' => 'search-picker',
'label' => 'Contact Person',
'searchPickerResultsProperty' => 'contactIdOptions',
'placeholder' => __('Search for contact person'),
'field_wrapper_class' => 'col-span-1',
],
]
]
];
}
[
'key' => '',
'value' => '',
'labels' => [] // optional
]
use WisamAlhennawi\LaraFormsBuilder\LaraFormComponent;
use WisamAlhennawi\LaraFormsBuilder\Traits\HasTabs;
class CustomerForm extends LaraFormComponent
{
use HasTabs;
public function mount(Customer $customer)
{
$this->mountForm($customer, [
'activeTab' => 'address-data',
'hasTabs' => true,
'isMultiStep' => true, // Optional if you want to use the multi-step form feature
]);
}
protected function fields(): array
{
return [
[
'key' => 'address-data',
'title' => __('Address Data'),
'content' => [
'group_info' => [
'group_wrapper_class' => 'grid grid-cols-4 gap-6',
'default_group_wrapper_class' => false
],
'fields' => [
// Fields for the 'Address Data' tab
// Example:
'company' => [
'type' => 'input',
'label' => __('models/customers.fields.company'),
'field_wrapper_class' => 'col-span-4',
],
// ... other fields
],
],
],
[
'key' => 'contact-data',
'title' => __('Contact Data'),
'content' => [
'group_info' => [
'group_wrapper_class' => 'grid grid-cols-6 gap-6',
'default_group_wrapper_class' => false
],
'fields' => [
// Fields for the 'Contact Data' tab
// Example:
'phone' => [
'type' => 'input',
'label' => __('customers.fields.phone'),
'field_wrapper_class' => 'col-span-2',
],
// ... other fields
],
],
],
// .. other tabs
];
}
// ... other component properties and methods
}
trans('A new entry has been created successfully.')
trans('Changes were saved successfully.')
'A new '.$modelName.' has been created successfully.'
'The '.$modelName.' has been updated successfully.'
'A new user has been created successfully.'
'The user has been updated successfully.'
bash
php artisan make:lara-forms-builder-setup
bash
php artisan vendor:publish --tag="lara-forms-builder-config"
js
export default {
content: [
'./config/lara-forms-builder.php',
],
theme: {
extend: {
colors: {
'primary': '', // #7c8e63
'secondary': '', // #aebf85
'danger': '' // #DC3545
},
},
},
};
bash
php artisan vendor:publish --tag="lara-forms-builder-assets"
bash
php artisan vendor:publish --tag="lara-forms-builder-translations"
bash
php artisan vendor:publish --tag="lara-forms-builder-views"