15/04
2018
Wallogit.com
2017 © Pedro Peláez
laravel gridview & active form from yii2
use Yii2 Gridview, ActiveForm, DetailView etc... in laravel, (*1)
echo \zacksleo\laravel\yii\grid\GridView::widget([
'dataProvider' => new zacksleo\laravel\yii\data\ActiveDataProvider([
'query' => \App\Models\User::query(),
]),
'columns' => [
'name',
'image',
[
'class' => zacksleo\laravel\yii\grid\ActionColumn::class,
],
],
]);
use php artisan make:request Person to make a RequestForm, (*2)
the class should implements RequestActiveForm, (*3)
model = \App\Models\Person::query()->find($id);
parent::__construct([], [], [], [], [], [], []);
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'img' => 'file'
];
}
public function getModel(): Model
{
return $this->model;
}
}
```
View
```
= $form->field($model, 'name')->textInput() ?>
= $form->field($model, 'img')->textInput() ?>
= Html::submitButton('Save',
['class' => $model->model->exists() ? 'btn btn-success' : 'btn btn-primary']) ?>
echo zacksleo\laravel\yii\widgets\DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
'image',
]
]);