PHP code example of rashidhamidov / model-form

1. Go to this page and download the library: Download rashidhamidov/model-form 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/ */

    

rashidhamidov / model-form example snippets


class Product extends Model
{
    use HasCrudForm;
}


private function setRootName()
    {
        return "product";
    }
    
private function setRulesStore()
    {
        return [
            'name'=>"

protected function formFields()
    {
        return [
            "name" => $this->setInputField('name', 'text', 'form-control', true, ''),
            "gender" => $this->setInputField('gender', 'radio', 'form-control', true, '', ["Male" => 'male', "Female" => "female"]),
            "phone" => $this->setInputField('phone', 'text', 'form-control phone-mask', false, ''),
            "detail" => $this->setTextAreaField('detail', 'form-control richtext', false, ''),
            "status" => $this->setSelectField('status', 'form-control', true, '', ['True'=>1, 'False'=>0]),
            "user" => $this->setForeignField('id','email','user_id', 'form-control', true, '', User::all()->toArray()),
            "date" => $this->setInputField('date', 'date', 'form-control', false, ''),
            "time" => $this->setInputField('time', 'time', 'form-control', false, ''),
        ];
    }

$model = new Product();

{{$model->form()}}

$model = Product::find($id);
$model->form($model);

Route::resource('product',ProductController::class);
//or
Route::post('/product',[ProductController::class,'store'])->name('product.store')
Route::put('/product/{product}',[ProductController::class,'update'])->name('product.store')

public function store(Request $request)
    {
        $model = new Product();
        $request->validate($model->getRules());
    }