turkmentv/app/Http/Controllers/Admin/MaterialCrudController.php

111 lines
5.6 KiB
PHP
Raw Normal View History

2019-05-11 00:27:49 +00:00
<?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\MaterialRequest as StoreRequest;
use App\Http\Requests\MaterialRequest as UpdateRequest;
use Backpack\CRUD\CrudPanel;
/**
* Class MaterialCrudController
* @package App\Http\Controllers\Admin
* @property-read CrudPanel $crud
*/
class MaterialCrudController extends CrudController
{
public function setup()
{
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\Material');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/material');
$this->crud->setEntityNameStrings('material', 'materials');
/*
|--------------------------------------------------------------------------
| CrudPanel Configuration
|--------------------------------------------------------------------------
*/
// TODO: remove setFromDb() and manually define Fields and Columns
//$this->crud->setFromDb();
$this->crud->addColumns([
['name' => 'title','type' => 'text', 'lable' => trans('admin.title')],
['name' => 'view','type' => 'text', 'lable' => trans('admin.view')],
['name' => 'rating','type' => 'text', 'lable' => trans('admin.like')],
['name' => 'price','type' => 'text', 'lable' => trans('admin.price')],
['name' => 'size','type' => 'text', 'lable' => trans('admin.size')],
['name' => 'duration','type' => 'text', 'lable' => trans('admin.duration')],
['name' => 'day_count','type' => 'text', 'lable' => trans('admin.day_count')],
['name' => 'download_count','type' => 'text', 'lable' => trans('admin.download_count')],
]);
$this->crud->addFields([
['name' => 'title','type' => 'text', 'lable' => trans('admin.title'),'tab' => trans('admin.material.firsttab')],
['name' => 'category_id', 'type' => 'select', 'entity' => 'category', 'attribute' =>'name', 'model' => 'App\Models\Category',
'lable'=>trans('admin.category'), 'tab' => trans('admin.material.firsttab')],
['name' => 'desc','type' => 'textarea', 'lable' => trans('admin.desc'),'tab' => trans('admin.material.firsttab')],
2019-06-26 05:45:32 +00:00
['suffix' => 'man.','attributes' => ["step" => "any"],'name' => 'price','type' => 'number', 'lable' => trans('admin.price'),'tab' => trans('admin.material.secondtab')],
['suffix'=>'Mb','attributes' => ["step" => "any"],'name' => 'size','type' => 'number', 'lable' => trans('admin.size'),'tab' => trans('admin.material.secondtab')],
2019-06-26 05:57:36 +00:00
['suffix'=>'min.','attributes' => ["step" => "any"],'name' => 'duration','type' => 'number', 'lable' => trans('admin.duration'),'tab' => trans('admin.material.secondtab')],
2019-05-11 00:27:49 +00:00
[ // image
'tab' => trans('admin.material.thirdtab'),
'label' => "Material Image",
'name' => "banner_url",
'type' => 'image',
'upload' => true,
'crop' => true, // set to true to allow cropping, false to disable
'aspect_ratio' => 2, // ommit or set to 0 to allow any aspect ratio
//'disk' => 'uploads', // in case you need to show images from a different disk
'prefix' => 'uploads/' // in case your db value is only the file name (no path), you can use this to prepend your path to the image src (in HTML), before it's shown to the user;
],
['name' => 'trailer_url','type' => 'browse', 'lable' => trans('admin.trailer_url'),'tab' => trans('admin.material.thirdtab')],
['name' => 'content_url','type' => 'browse', 'lable' => trans('admin.content_url'),'tab' => trans('admin.material.thirdtab')],
['name' => 'day_count','type' => 'number', 'lable' => trans('admin.day_count'),'tab' => trans('admin.material.secondtab')],
['name' => 'download_count','type' => 'number', 'lable' => trans('admin.download_count'),'tab' => trans('admin.material.secondtab')],
2019-05-13 11:40:38 +00:00
[ // Table
'name' => 'details',
'label' => trans('admin.material.extras'),
'type' => 'table',
'entity_singular' => 'detail', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'desc' => 'Description'
],
'tab' => trans('admin.material.fourthtab'),
],
2019-05-11 00:27:49 +00:00
]);
// add asterisk for fields that are required in MaterialRequest
$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;
}
}