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

123 lines
4.2 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\ClientRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class ClientCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class ClientCrudController 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('clients'))){
$this->crud->denyAccess(['delete', 'update']);
}
CRUD::setModel(\App\Models\Client::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/client');
CRUD::setEntityNameStrings(trans('app.client.title'), trans('app.client.list_title'));
$this->crud->addFilter([
'name' => 'is_verified',
'type' => 'dropdown',
'label' => trans('app.client.is_verified')
], [
1 => trans('app.yes'),
0 => trans('app.no'),
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'is_verified', $value);
});
$this->crud->addFilter([
'name' => 'is_suspended',
'type' => 'dropdown',
'label' => trans('app.client.is_suspended'),
], [
1 => trans('app.yes'),
0 => trans('app.no'),
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'is_suspended', $value);
});
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
CRUD::addColumns([
['name' => 'firstname','type'=>'text','label'=> trans('app.client.firstname')],
['name' => 'lastname','type'=>'text','label'=> trans('app.client.lastname')],
['name' => 'email','type'=>'text','label'=> trans('app.client.email')],
[
'name' => 'is_verified',
'type' => 'radio',
'label' => trans('app.client.is_verified'),
'options' => [
1 => trans('app.yes'),
0 => trans('app.no'),
]
],
[
'name' => 'is_suspended',
'type' => 'radio',
'label' => trans('app.client.is_suspended'),
'options' => [
1 => trans('app.yes'),
0 => trans('app.no'),
]
]
]);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(ClientRequest::class);
CRUD::addFields([
['name' => 'firstname','type'=>'text','label'=> trans('app.client.firstname')],
['name' => 'lastname','type'=>'text','label'=> trans('app.client.lastname')],
['name' => 'email','type'=>'text','label'=> trans('app.client.email')],
['name' => 'is_suspended', 'type' => 'switch', 'label' => trans('app.client.is_suspended')],
['name' => 'is_verified', 'type' => 'switch', 'label' => trans('app.client.is_verified')]
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}