PHP Classes

File: CmsController.php

Recommend this page to a friend!
  Classes of Luciano Filho  >  Laravel Auto Generated Form  >  CmsController.php  >  Download  
File: CmsController.php
Role: Example script
Content type: text/plain
Description: Example of usage class
Class: Laravel Auto Generated Form
Create forms from Laravel model classes
Author: By
Last change:
Date: 6 years ago
Size: 1,669 bytes
 

Contents

Class file image Download
<?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');
    }
}