PHP Classes

Laravel Auto Generated Form: Create forms from Laravel model classes

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 166 All time: 8,898 This week: 455Up
Version License PHP version Categories
laravel-autoform 1.6Artistic License5.5HTML, PHP 5, Databases
Description 

Author

This class can create forms from Laravel model classes.

It takes a Laravel model class object and retrieve the object fields so it can generate a form to let the users enter values to create new objects of the model class.

The class automatically guesses the types of form inputs to create based on the field types and names.

Applications can extend the Laravel model class with the necessary information on fields to define all the details of the form to be created including relationships and validation rules.

The class can render the generated form and return the respective HTML code.

Innovation Award
PHP Programming Innovation award nominee
March 2016
Number 7


Prize: SourceGuarding PHP encoder tool
Model classes often contain metadata about the information that they store and retrieve from some database container.

This class can use metadata contained in model classes used by the Laravel framework, so it can get all the details to generate forms to store and retrieve information managed by those model classes.

Manuel Lemos
Picture of Luciano Filho
  Performance   Level  
Name: Luciano Filho <contact>
Classes: 3 packages by
Country: Brazil Brazil
Age: 33
All time rank: 3268248 in Brazil Brazil
Week rank: 192 Up14 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

namespace App\Http\Controllers\Cms;

use
Illuminate\Foundation\Bus\DispatchesJobs;
use
Illuminate\Routing\Controller as BaseController;
use
Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use
Illuminate\Http\Request;
use
Auth;

use
App\Autoform;

class
CmsController extends Controller
{
    use
AuthorizesRequests, DispatchesJobs;
    function
__construct()
    {
       
parent::__construct();
    }

    public function
index(Request $request)
    {
       
$this->setTemplate('cms.pages.home.index');
    }

    public function
form(Request $request, $model, $id = 'add')
    {
        if(
$id == 'add')
        {
           
$id = null;
        }

       
$modelAction = $model;
        if(!
is_null($id))
        {
           
$modelAction = $modelAction.'/'.$id;
        }

       
$this->addJavaScriptData('modelName', $modelAction);
       
$model = $this->getModel($model);

       
$fields = Autoform::loadFromModel($model, 'form_'.$model->modelName, 'POST', 'cms/api/'.$model->modelName, $id);

       
$this->addModules('form');

       
$this->addData('model', $model);
       
$this->addData('form', $fields);
       
$this->addData('modelName', $model->modelName);

       
$this->setPageTitle('Listar '.$model->modelName);
       
$this->setTemplate('cms.pages.generic.form');
    }

    public function
listing(Request $request, $model)
    {
       
$this->addJavaScriptData('modelName', $model);
       
$model = $this->getModel($model);

       
$this->addModules('list');

       
$fields = Autoform::loadFromModel($model, 'form_'.$model->modelName, 'POST', 'cms/api/'.$model->modelName);
       
$this->addData('model', $model);
       
$this->addData('modelName', $model->modelName);
       
$this->addData('list', $model->fields);

       
$this->setPageTitle('Salvar '.$model->modelName);
       
$this->setTemplate('cms.pages.generic.list');
    }
}


  Files folder image Files (3)  
File Role Description
Plain text file Autoform.php Class Class
Accessible without login Plain text file CmsController.php Example Example of usage class
Plain text file CmsUserType.php Class Example of usage class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:166
This week:0
All time:8,898
This week:455Up