exchange/app/Http/Controllers/Admin/DocumentCrudController.php

64 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\DocumentRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class DocumentCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class DocumentCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation;
public function setup()
{
$this->crud->setModel('App\Models\Document');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/document');
$this->crud->setEntityNameStrings(trans('backpack::model.document'), trans('backpack::model.documents'));
}
protected function setupListOperation()
{
// TODO: remove setFromDb() and manually define Columns, maybe Filters
CRUD::column('document_category_id')->type('select')->entity('documentCategory')->model('App\Models\DocumentCategory')->attribute('title');
CRUD::column('title');
CRUD::column('file');
CRUD::column('page');
}
protected function setupCreateOperation()
{
$this->crud->setValidation(DocumentRequest::class);
// TODO: remove setFromDb() and manually define Fields
CRUD::field('document_category_id')->type('select')->entity('documentCategory')->model('App\Models\DocumentCategory')->attribute('title');
CRUD::field('title');
CRUD::field('file')->type('upload')->upload(true);
CRUD::field('page');
}
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
protected function setupReorderOperation()
{
// define which model attribute will be shown on draggable elements
$this->crud->set('reorder.label', 'title');
// define how deep the admin is allowed to nest the items
// for infinite levels, set it to 0
$this->crud->set('reorder.max_level', 1);
}
}