Files
coreality-inc/app/Http/Controllers/Admin/HomeCarouselCrudController.php
ericli1018 6dfe3e0677 release
2025-06-13 12:24:35 +08:00

155 lines
4.9 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\HomeCarouselRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class HomeCarouselCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class HomeCarouselCrudController 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;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation { destroy as traitDestroy; }
public function destroy($id)
{
//CRUD::hasAccessOrFail('delete');
if (\App\Models\HomeCarousel::count() <= 7)
{
$this->crud->allowAccess('create');
}
return CRUD::delete($id);
}
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\App\Models\HomeCarousel::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/home-carousel');
CRUD::setEntityNameStrings(trans('backend.home_carousel.content.item'), trans('backend.home_carousel.content.items'));
}
protected function setupReorderOperation()
{
CRUD::set('reorder.label', 'title');
CRUD::set('reorder.max_level', 1);
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
if (! $this->crud->getRequest()->has('order')){
$this->crud->orderBy('lft', 'asc')->orderBy('id', 'desc');
}
if (\App\Models\HomeCarousel::count() >= 6)
{
$this->crud->denyAccess('create');
}
else
{
$this->crud->allowAccess('create');
}
$this->crud->addColumns([
[
'name' => 'is_front_show',
'label' => trans('backend.columnName.is_front_show'),
'type' => 'checkbox'
],
[
'name' => 'title',
'label' => trans('backend.columnName.title'),
'type' => 'text'
]
]);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(HomeCarouselRequest::class);
CRUD::addFields([
[
'name' => 'is_front_show',
'label' => trans('backend.columnName.is_front_show'),
'type' => 'boolean',
'default' => true,
],
[
'name' => 'title',
'label' => trans('backend.columnName.title'),
'type' => 'text'
],
[
'name' => 'body',
'label' => trans('backend.columnName.body'),
'type' => 'textarea'
],
[
'name' => 'link',
'label' => trans('backend.columnName.link'),
'type' => 'text'
],
[
'name' => 'featured_photos',
'label' => trans('backend.columnName.featured_img'),
'type' => 'upload_img_multiple',
'upload' => true,
'disk' => 'public',
'hint' => '',
'qty' => 1, // 0=no limit, >0=limit
'showSingleChoise' => '0', // 0=hidden, 1=show(default)
'showComment' => '0', // 0=hidden, 1=show(default)
],
[
'name' => 'photos',
'label' => trans('backend.columnName.cover'),
'type' => 'upload_img_multiple',
'upload' => true,
'disk' => 'public',
'hint' => '',
'qty' => 1, // 0=no limit, >0=limit
'showSingleChoise' => '0', // 0=hidden, 1=show(default)
'showComment' => '0', // 0=hidden, 1=show(default)
],
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}