97 lines
4.1 KiB
PHP
97 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController;
|
|
|
|
// VALIDATION: change the requests to match your own file names if you need form validation
|
|
use App\Http\Requests\PageRequest as StoreRequest;
|
|
use App\Http\Requests\PageRequest as UpdateRequest;
|
|
use Backpack\CRUD\CrudPanel;
|
|
|
|
/**
|
|
* Class PageCrudController
|
|
* @package App\Http\Controllers\Admin
|
|
* @property-read CrudPanel $crud
|
|
*/
|
|
class PageCrudController extends CrudController
|
|
{
|
|
public function setup()
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| CrudPanel Basic Information
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
$this->crud->setModel('App\Models\Page');
|
|
$this->crud->setRoute(config('backpack.base.route_prefix') . '/page');
|
|
$this->crud->setEntityNameStrings('page', 'pages');
|
|
$this->crud->orderBy('updated_at', 'DESC');
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| CrudPanel Configuration
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
// TODO: remove setFromDb() and manually define Fields and Columns
|
|
//$this->crud->setFromDb();
|
|
|
|
$this->crud->addColumns([
|
|
['name' => 'title','type' => 'text', 'label' => 'Title'],
|
|
['name' => 'keywords','type' => 'text', 'label' => 'Keywords'],
|
|
['name' => 'meta_description','type' => 'text', 'label' => 'Meta description'],
|
|
['name' => 'description','type' => 'text', 'label' => 'Description'],
|
|
['name' => 'menu_id', 'type' => 'select', 'entity' => 'menu', 'attribute' =>'name', 'model' => 'App\Models\Menu',
|
|
'label'=>'Menu'],
|
|
|
|
]);
|
|
|
|
$this->crud->addFields([
|
|
['name' => 'title','type' => 'text', 'label' => 'Title'],
|
|
['name' => 'keywords','type' => 'text', 'label' => 'Keywords'],
|
|
['name' => 'meta_description','type' => 'text', 'label' => 'Meta description'],
|
|
['name' => 'description','type' => 'summernote', 'label' => 'Description'],
|
|
['name' => 'menu_id', 'type' => 'select', 'entity' => 'menu', 'attribute' =>'name', 'model' => 'App\Models\Menu',
|
|
'label'=>'Menu'],
|
|
['name' => 'group','type' => 'checkbox', 'label' => 'Group'],
|
|
// ['name' => 'group_id', 'type' => 'select', 'entity' => 'group', 'attribute' =>'name', 'model' => 'App\Models\Group',
|
|
// 'lable'=>'Group Name'],
|
|
// [ // Select2Multiple = n-n relationship (with pivot table)
|
|
// 'label' => "Slider",
|
|
// 'type' => 'select2_multiple',
|
|
// 'name' => 'sliders', // the method that defines the relationship in your Model
|
|
// 'entity' => 'sliders', // the method that defines the relationship in your Model
|
|
// 'attribute' => 'page_id', // foreign key attribute that is shown to user
|
|
// 'model' => "App\Models\Slider", // foreign key model
|
|
// 'pivot' => false, // on create&update, do you need to add/delete pivot table entries?
|
|
// // 'select_all' => true, // show Select All and Clear buttons?
|
|
|
|
// ]
|
|
|
|
]);
|
|
|
|
// add asterisk for fields that are required in PageRequest
|
|
$this->crud->setRequiredFields(StoreRequest::class, 'create');
|
|
$this->crud->setRequiredFields(UpdateRequest::class, 'edit');
|
|
}
|
|
|
|
public function store(StoreRequest $request)
|
|
{
|
|
// your additional operations before save here
|
|
$redirect_location = parent::storeCrud($request);
|
|
// your additional operations after save here
|
|
// use $this->data['entry'] or $this->crud->entry
|
|
return $redirect_location;
|
|
}
|
|
|
|
public function update(UpdateRequest $request)
|
|
{
|
|
// your additional operations before save here
|
|
$redirect_location = parent::updateCrud($request);
|
|
// your additional operations after save here
|
|
// use $this->data['entry'] or $this->crud->entry
|
|
return $redirect_location;
|
|
}
|
|
}
|