98 lines
4.2 KiB
PHP
98 lines
4.2 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\PageadRequest as StoreRequest;
|
|
use App\Http\Requests\PageadRequest as UpdateRequest;
|
|
use Backpack\CRUD\CrudPanel;
|
|
|
|
/**
|
|
* Class PageadCrudController
|
|
* @package App\Http\Controllers\Admin
|
|
* @property-read CrudPanel $crud
|
|
*/
|
|
class PageadCrudController extends CrudController
|
|
{
|
|
public function setup()
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| CrudPanel Basic Information
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
$this->crud->setModel('App\Models\Pagead');
|
|
$this->crud->setRoute(config('backpack.base.route_prefix') . '/pagead');
|
|
$this->crud->setEntityNameStrings('pagead', 'pageads');
|
|
$this->crud->orderBy('updated_at', 'DESC');
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| CrudPanel Configuration
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
// TODO: remove setFromDb() and manually define Fields and Columns
|
|
//$this->crud->setFromDb();
|
|
|
|
$this->crud->addColumns([
|
|
['name' => 'page_id', 'type' => 'select', 'entity' => 'page', 'attribute' =>'title', 'model' => 'App\Models\Page',
|
|
'lable'=>'Page'],
|
|
['name' => 'name','type' => 'text', 'lable' => 'Name'],
|
|
['name' => 'adv_type', 'type' => 'enum', 'label' => 'Adv Type'],
|
|
['name' => 'img_url','type' => 'text', 'lable' => 'Image'],
|
|
]);
|
|
|
|
$this->crud->addFields([
|
|
['name' => 'page_id', 'type' => 'select', 'entity' => 'page', 'attribute' =>'title', 'model' => 'App\Models\Page',
|
|
'lable'=>'Page'],
|
|
['name' => 'name','type' => 'text', 'lable' => 'Name'],
|
|
['name' => 'adv_type', 'type' => 'enum', 'label' => 'Adv Type'],
|
|
[ 'label' => "Image",
|
|
'name' => "img_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;
|
|
],
|
|
[ 'label' => "Poster images for video",
|
|
'name' => "poster_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' => 'video_url','type' => 'browse', 'lable' => 'Video'],
|
|
|
|
]);
|
|
|
|
// add asterisk for fields that are required in PageadRequest
|
|
$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;
|
|
}
|
|
}
|