PHP code example of administrcms / form

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

    

administrcms / form example snippets


// in app.php
'providers' => [
    // ...
    Administr\Form\FormServiceProvider::class,
    // ...
],

// in AppServiceProvider
public function register()
{
    $this->app->register(\Administr\Form\FormServiceProvider::class);
}




namespace App\Http\Controllers;

use App\Http\Forms\MyForm;
use App\MyModel;

class MyController extends Controller {
    public function create(MyForm $form)
    {
        $form->method = 'post';
        $form->action = route('my-form-action');
        
        return view('my-view', ['form' => $form]);
    }
    
    public function store(MyForm $form)
    {
        MyModel::create($form->request()->all());
    }
    
    public function edit($id, MyForm $form)
    {
        $form->method = 'put';
        $form->action = route('my-form-update', [$id]);
        
        // The datasource can be an array, Collection or Model
        $form->dataSource(MyModel::find($id));
        
        return view('my-view', ['form' => $form]);
    }
    
    public function update($id, MyForm $form)
    {
        $model = MyModel::find($id);
        
        $model->update($form->request()->all());
    }
}



namespace App\Http\Forms;

use Administr\Form\Field\RadioGroup;
use Administr\Form\Form;
use Administr\Form\FormBuilder;

class TeamForm extends Form
{

    /**
     * Define the validation rules for the form.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'      => '  $group
                    ->radio('да', ['value' => 1])
                    ->radio('не', ['value' => 0]);
            })
            ->submit('save', 'Save');
    }
}

php artisan vendor:publish --provider="Administr\Form\FormServiceProvider"