2017 © Pedro Peláez
 

library laravel-form

Use Symfony Form component with Laravel framework

image

brainfab/laravel-form

Use Symfony Form component with Laravel framework

  • Friday, January 27, 2017
  • by brainfab
  • Repository
  • 2 Watchers
  • 1 Stars
  • 7 Installations
  • HTML
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Use Symfony Form component with Laravel framework

Latest Stable Version Total Downloads Latest Unstable Version License Code Climate, (*1)

Under construction, (*2)

Installation

Require this package with composer:, (*3)

composer require brainfab/laravel-form, (*4)

After updating composer, add the ServiceProvider to the providers array in config/app.php, (*5)

Brainfab\LaravelForm\LaravelFormsServiceProvider::class,, (*6)

Add the Facade to the aliases array in config/app.php, (*7)

'FormFactory' => Brainfab\LaravelForm\Facades\FormFactory::class,, (*8)

(optional) Copy the package config to your local config with the publish command:, (*9)

php artisan vendor:publish --tag=config, (*10)

(optional) Copy the package views to your local views/vendor folder with the publish command:, (*11)

php artisan vendor:publish --tag=views, (*12)

Console

Generate form class: php artisan make:form 'App\Forms\UserForm', (*13)

Usage example

app/Forms/UserForm.php, (*14)

<?php

namespace App\Forms;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class UserForm extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', TextType::class, [
            'rules' => 'required|min:6',
            'label' => 'Name'
        ]);

        $builder->add('email', EmailType::class, [
            'rules' => 'required|email',
            'label' => 'Email'
        ]);

        $builder->add('save_btn', SubmitType::class, [
            'label' => 'Save'
        ]);
    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        //set default options
        $resolver->setDefaults([]);
    }
}

app/Http/Controllers/UserController.php, (*15)

<?php

namespace App\Http\Controllers;

use App\Forms\UserForm;
use Brainfab\LaravelForm\Controller\LaravelForm;
use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    use LaravelForm;

    public function index(Request $request)
    {
        $user = new User();

        $form = $this->createForm(TestForm::class, $user);

        if ($request->isMethod('post')) {
            //submit request
            $form->handleRequest($request);

            if ($form->isValid()) {
                $user->save();
            }
        }

        return view('users', [
            'form' => $form->createView()
        ]);
    }
}

resources/views/users.blade.php, (*16)

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>LaravelForm</title>
</head>
<body>

    {{form($form)}}

</body>
</html>

The Versions

27/01 2017

dev-master

9999999-dev

Use Symfony Form component with Laravel framework

  Sources   Download

MIT

The Requires

 

laravel framework form symfony

16/01 2017

dev-develop

dev-develop

Use Symfony Form component with Laravel framework

  Sources   Download

MIT

The Requires

 

laravel framework form symfony

16/01 2017

dev-feature/issue-1

dev-feature/issue-1

Use Symfony Form component with Laravel framework

  Sources   Download

MIT

The Requires

 

laravel framework form symfony

16/01 2017

dev-feature/issue-2

dev-feature/issue-2

Use Symfony Form component with Laravel framework

  Sources   Download

MIT

The Requires

 

laravel framework form symfony