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

134 lines
4.6 KiB
PHP
Raw Normal View History

2022-06-24 11:56:01 +00:00
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\ClientRequest;
2023-03-29 23:17:29 +00:00
use App\Models\Client;
2022-06-24 11:56:01 +00:00
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
2023-03-29 23:17:29 +00:00
use Illuminate\Http\Request;
2022-06-24 11:56:01 +00:00
/**
* 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;
2022-11-08 09:07:29 +00:00
// use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
2022-06-24 11:56:01 +00:00
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.
*
2022-06-24 11:56:01 +00:00
* @return void
*/
public function setup()
{
2022-11-14 09:54:17 +00:00
if(!(backpack_user()->hasPermissionTo('clients'))){
2022-11-16 12:05:04 +00:00
$this->crud->denyAccess(['delete', 'update']);
2022-11-14 09:54:17 +00:00
}
2022-06-24 11:56:01 +00:00
CRUD::setModel(\App\Models\Client::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/client');
2022-11-08 08:34:11 +00:00
CRUD::setEntityNameStrings(trans('app.client.title'), trans('app.client.list_title'));
2022-09-21 12:31:57 +00:00
$this->crud->addFilter([
'name' => 'is_verified',
'type' => 'dropdown',
2022-11-08 07:37:23 +00:00
'label' => trans('app.client.is_verified')
2022-09-21 12:31:57 +00:00
], [
2022-11-08 07:37:23 +00:00
1 => trans('app.yes'),
0 => trans('app.no'),
2022-09-21 12:31:57 +00:00
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'is_verified', $value);
});
$this->crud->addFilter([
'name' => 'is_suspended',
'type' => 'dropdown',
2022-11-08 07:37:23 +00:00
'label' => trans('app.client.is_suspended'),
2022-09-21 12:31:57 +00:00
], [
2022-11-08 07:37:23 +00:00
1 => trans('app.yes'),
0 => trans('app.no'),
2022-09-21 12:31:57 +00:00
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'is_suspended', $value);
});
2022-06-24 11:56:01 +00:00
}
/**
* Define what happens when the List operation is loaded.
*
2022-06-24 11:56:01 +00:00
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
2022-09-21 12:31:57 +00:00
CRUD::addColumns([
2022-11-08 09:18:25 +00:00
['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')],
2022-09-21 12:31:57 +00:00
[
'name' => 'is_verified',
'type' => 'radio',
2022-11-08 07:37:23 +00:00
'label' => trans('app.client.is_verified'),
2022-09-21 12:31:57 +00:00
'options' => [
2022-11-08 07:37:23 +00:00
1 => trans('app.yes'),
0 => trans('app.no'),
2022-09-21 12:31:57 +00:00
]
],
[
'name' => 'is_suspended',
'type' => 'radio',
2022-11-08 07:37:23 +00:00
'label' => trans('app.client.is_suspended'),
2022-09-21 12:31:57 +00:00
'options' => [
2022-11-08 07:37:23 +00:00
1 => trans('app.yes'),
0 => trans('app.no'),
2022-09-21 12:31:57 +00:00
]
]
]);
2022-06-24 11:56:01 +00:00
}
/**
* Define what happens when the Create operation is loaded.
*
2022-06-24 11:56:01 +00:00
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
2022-11-08 09:18:25 +00:00
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')]
]);
}
2022-06-24 11:56:01 +00:00
/**
* Define what happens when the Update operation is loaded.
*
2022-06-24 11:56:01 +00:00
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
2022-11-08 09:18:25 +00:00
$this->setupCreateOperation();
2022-06-24 11:56:01 +00:00
}
2023-03-29 23:17:29 +00:00
public function createClient(Request $request){
$data = $request->only('firstname', 'lastname', 'email', 'password', 'account_id');
$data['is_verified'] = false;
$data['is_suspended'] = false;
$client = new Client($data);
$client->save();
return redirect()->to('/admin/preview/' . $request->account_id . '#users');
}
2022-06-24 11:56:01 +00:00
}