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

91 lines
2.5 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\MessageRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class MessageCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class MessageCrudController 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()
{
if(!(backpack_user()->hasPermissionTo('tickets'))){
$this->crud->denyAccess(['delete', 'update']);
}
CRUD::setModel(\App\Models\Message::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/message');
CRUD::setEntityNameStrings('message', 'messages');
}
/**
* 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->setFromDb();
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(MessageRequest::class);
$this->crud->addFields([
[
'name' => 'content',
'type' => 'text',
'label' => 'Content'
],
[
'name' => 'ticket_id',
'type' => 'select',
'entity' => 'ticket',
'model' => 'App\Models\Ticket',
'attribute' => 'title',
'label' => 'Ticket'
],
[
'name' => 'is_client',
'label' => 'Is client?',
'type' => 'checkbox'
],
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}