Skip to content
Alexey Dobrovolsky edited this page Sep 8, 2020 · 9 revisions

Introduction

This package was created by developer for developers and web masters. The main goal it's easy building and flexible extensioning of forms. With this package you can create and customize forms, fill their fields with data from any source with using additional data mappers. Each field is a kind of component like in some reactive JS frameworks, they are encapsulated from outside logic and may be reusable.

Template preparation

You can use your custom template or any ready to use bootstrap admin panel, Admin LTE as an example. To display your form you need to use {!! !!} to display form html without escaping special characters

Easy using with laravel Eloquent models

To create a CRUD operations you only need to:

  1. Write array of configuration of your form.
  2. Write validation FormRequest or other validation.
  3. Prepare your Eloquent model fillable fields.
  4. Prepare routes.
  5. Prepare your controller actions (see below).

Your create action might look like this:

    public function create()
    {
        $form = \EasyForm::create('page');
        return view('form.template')->with(['form' => $form]);
    }

Your store action might look like this:

    public function store(StorePageRequest $request)
    {
        Page::create($request->validated());

        $request->session()->flash('status', 'Page was created successful!');
        return redirect('page.list');
    }

Your store and update action method might use DataMapper if you need to handle data before save data in eloquent model.

Your edit action might look like this:

    public function edit(Page $page)
    {
        $form = \EasyForm::create('page', new EloquentDataMapper($page));
        return view('form.template')->with(['form' => $form]);
    }

Your update action might look like this:

    public function update(StorePageRequest $request, Page $page)
    {
        $page->update($request->validated());

        $request->session()->flash('status', 'Page was updated successful!');
        return redirect('page.list');
    }

As you can see different between create and edit actions only in using data mapper and data source, it's need for filling your form with data of existing eloquent model.

Clone this wiki locally