birzha-legalizasia/app/Http/Controllers/Admin/TicketCrudController.php

149 lines
4.5 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\TicketRequest;
use App\Models\Status;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class TicketCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class TicketCrudController 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;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\App\Models\Ticket::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/ticket');
CRUD::setEntityNameStrings('ticket', 'tickets');
// select2 filter
$this->crud->addFilter([
'name' => 'status',
'type' => 'select2',
'label' => 'Status'
], function () {
return Status::get()->pluck('name', 'id')->toArray();
}, function ($value) { // if the filter is active
$this->crud->addClause('where', 'status_id', $value);
});
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->crud->addColumns([
[
'name' => 'content',
'type' => 'text',
'label' => 'Content'
],
[
'name' => 'title',
'type' => 'text',
'label' => 'Title'
],
[
'name' => 'client_id',
'entity' => 'client',
'type' => 'select',
'label' => 'Client',
'attribute' => 'email',
'model' => 'App\Models\Client'
],
[
'name' => 'status',
'type' => 'status',
'label' => 'Status'
],
]);
$this->crud->addButtonFromModelFunction('line', 'messages', 'messagesOfTicket', 'beginning');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(TicketRequest::class);
$this->crud->addFields([
[
'name' => 'title',
'type' => 'text',
'label' => 'Title'
],
[
'name' => 'content',
'type' => 'summernote',
'label' => 'Content'
],
[
'name' => 'client_id',
'entity' => 'client',
'type' => 'select',
'label' => 'Client',
'attribute' => 'email',
'model' => 'App\Models\Client'
],
[
'name' => 'category_id',
'entity' => 'category',
'type' => 'select',
'label' => 'Category',
'attribute' => 'name',
'model' => 'App\Models\Category'
],
[
'name' => 'status_id',
'entity' => 'status',
'type' => 'select',
'label' => 'Status',
'attribute' => 'name',
'model' => 'App\Models\Status'
],
[
'name' => 'last_sender',
'label' => 'Last sender',
'type' => 'select_from_array',
'options' => ['admin' => 'admin', 'client' => 'client'],
'allows_null' => false,
'default' => 'admin'
]
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}