PHP code example of sinevia / laravel-helpers
1. Go to this page and download the library: Download sinevia/laravel-helpers 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/ */
sinevia / laravel-helpers example snippets
private function getFields($options = []) {
$model = $options['model'] ?? null;
$fields = [
[
'type' => 'html',
'html' => '<style>.btn-success { width:100%; padding:10px;}</style>',
],
[
'type' => 'html',
'html' => '<div class="col-sm-12"><h1>First Heading</h1></div>',
],
[
'type' => 'text',
'name' => 'TextField',
'label' => 'Text Field',
'width' => 12,
'rule' => ' 'value' => is_null($model) ? null : '' . $model->HiddenField,
],
[
'type' => 'select',
'name' => 'SelectField',
'label' => 'Select Field',
'options' => [''=>'','1'=>'1','2'=>'2',],
'width' => 12,
'rule' => '
$form = \Sinevia\LaravelHelpers\Ui::formBuild($this->getFields(), [
'button.apply.show' => 'yes',
'button.cancel.show' => 'yes',
'button.cancel.link' => '/back',
'button.cancel.icon' => '<i class="fas fa-chevron-left"></i>',
'button.apply.icon' => '<i class="fas fa-check"></i>',
'button.save.icon' => '<i class="fas fa-save"></i>',
])
->toHtml();
$validOrErrorMessage = \Sinevia\LaravelHelpers\Ui::formValidate($this->formFields());
if ($validOrErrorMessage !== true) {
return back()->withErrors($validOrErrorMessage)->withInput(request()->all());
}
$formValues = \App\Helpers\Ui::formFieldValues($this->getFields());
\App\Models\YourModel::unguard();
$yourModel = \App\Models\YourModel::create($formValues);
if(is_null($yourModel)){
return back()->withErrors('Model creation failed')->withInput(request()->all());
}
if (request('form_action') == 'apply') {
return redirect('/update?ModelId=' . $yourModel->Id]))
->withSuccess('Model successfully created');
}
return redirect('/list')->withSuccess('Model successfully created');