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

176 lines
7.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\ApplicationRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class ApplicationCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class ApplicationCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
2022-11-08 08:11:10 +00:00
// 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()
{
2022-11-14 09:54:17 +00:00
if(!(backpack_user()->hasPermissionTo('applications'))){
2022-11-16 12:05:04 +00:00
$this->crud->denyAccess(['delete', 'update']);
2022-11-14 09:54:17 +00:00
}
CRUD::setModel(\App\Models\Application::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/application');
2022-11-08 07:37:23 +00:00
CRUD::setEntityNameStrings('application', trans('app.application.list_title'));
$this->crud->addFilter([
'name' => 'state',
'type' => 'dropdown',
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.state')
], [
2022-11-08 07:37:23 +00:00
'new' => trans('app.application.new'),
'applied' => trans('app.application.applied'),
2022-11-18 12:10:51 +00:00
// 'accepted' => trans('app.application.accepted'),
2022-11-08 07:37:23 +00:00
'refine' => trans('app.application.refine'),
'approved' => trans('app.application.approved'),
'archive' => trans('app.application.archived')
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'state', $value);
});
$this->crud->addFilter([
'type' => 'date_range',
'name' => 'from_to',
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.date_filter'),
],
false,
function ($value) { // if the filter is active, apply these constraints
$dates = json_decode($value);
$this->crud->addClause('where', 'created_at', '>=', $dates->from);
$this->crud->addClause('where', 'created_at', '<=', $dates->to . ' 23:59:59');
});
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
2022-09-23 13:26:59 +00:00
$this->crud->addColumns([
[
'name' => 'profile',
'type' => 'account_profile_name',
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.account'),
2022-09-23 13:26:59 +00:00
],
2022-09-30 07:52:56 +00:00
[ // SelectMultiple = n-n relationship (with pivot table)
2022-11-09 04:53:05 +00:00
'label' => trans('app.application.account_type'),
2022-09-30 07:52:56 +00:00
'type' => 'select',
'name' => 'account_type', // the method that defines the relationship in your Model
'entity' => 'account', // the method that defines the relationship in your Model
'model' => "App\Models\Account", // foreign key model
'attribute' => 'type',
],
[ // SelectMultiple = n-n relationship (with pivot table)
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.leg_number'),
2022-09-30 07:52:56 +00:00
'type' => 'select',
'name' => 'account_legnumber', // the method that defines the relationship in your Model
'entity' => 'account', // the method that defines the relationship in your Model
'model' => "App\Models\Account", // foreign key model
'attribute' => 'legalization_number',
],
[ // SelectMultiple = n-n relationship (with pivot table)
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.expires_at'),
2022-09-30 07:52:56 +00:00
'type' => 'select',
'name' => 'account_exp_date', // the method that defines the relationship in your Model
'entity' => 'account', // the method that defines the relationship in your Model
'model' => "App\Models\Account", // foreign key model
'attribute' => 'expires_at',
],
2022-09-23 13:26:59 +00:00
[
'name' => 'state',
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.state'),
'type' => 'badge',
],
[
'name' => 'created_at',
2022-11-08 07:37:23 +00:00
'label' => trans('app.application.created_at'),
2022-09-23 13:26:59 +00:00
]
]);
2022-09-30 08:58:33 +00:00
$this->crud->addButtonFromModelFunction('line', 'preview_button', 'preview', 'beginning');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
2022-11-08 08:11:10 +00:00
// protected function setupCreateOperation()
// {
// CRUD::setValidation(ApplicationRequest::class);
// $this->crud->addFields([
// [ // SelectMultiple = n-n relationship (with pivot table)
// 'label' => trans('app.application.account'),
// 'type' => 'custom_select_account',
// 'name' => 'account_id', // the method that defines the relationship in your Model
// 'entity' => 'account', // the method that defines the relationship in your Model
// 'model' => "App\Models\Account", // foreign key model
// 'attribute_1' => 'name', // foreign key attribute that is shown to user
// 'attribute_2' => 'surname',
// ],
// [
// 'name' => 'state',
// 'label' => trans('app.application.state'),
// 'type' => 'select_from_array',
// 'options' => [
// 'new' => trans('app.application.new'),
// 'applied' => trans('app.application.applied'),
// 'refine' => trans('app.application.refine'),
// 'approved' => trans('app.application.approved'),
// 'archive' => trans('app.application.archived')
// ]
// ]
// ]);
// }
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
CRUD::setValidation(ApplicationRequest::class);
$this->crud->addFields([
[
'name' => 'state',
'label' => 'State',
'type' => 'select_from_array',
'options' => [
2022-11-08 07:37:23 +00:00
'new' => trans('app.application.new'),
'applied' => trans('app.application.applied'),
'refine' => trans('app.application.refine'),
'approved' => trans('app.application.approved'),
'archive' => trans('app.application.archived')
]
]
]);
}
}