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

171 lines
6.3 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;
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\Application::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/application');
CRUD::setEntityNameStrings('application', 'applications');
$this->crud->addFilter([
'name' => 'state',
'type' => 'dropdown',
'label' => 'State'
], [
'new' => 'new',
'applied' => 'applied',
2022-11-07 11:49:04 +00:00
'refine' => 'refine',
'approved' => 'approved',
'archived' => 'archived'
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'state', $value);
});
$this->crud->addFilter([
'type' => 'date_range',
'name' => 'from_to',
'label' => 'Created at from-to'
],
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-09-23 13:26:59 +00:00
'label' => 'Account',
],
2022-09-30 07:52:56 +00:00
[ // SelectMultiple = n-n relationship (with pivot table)
'label' => "Account type",
'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)
'label' => "Legalization number",
'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)
'label' => "Legalization number",
'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',
'label' => 'State',
'type' => 'badge',
],
[
'name' => '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
*/
protected function setupCreateOperation()
{
CRUD::setValidation(ApplicationRequest::class);
$this->crud->addFields([
[ // SelectMultiple = n-n relationship (with pivot table)
'label' => "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',
2022-09-13 22:21:05 +00:00
],
[
'name' => 'state',
'label' => 'State',
'type' => 'select_from_array',
'options' => [
'new' => 'New',
'applied' => 'Applied',
'refine' => 'Refine',
'approved' => 'Approved',
'archive' => 'Archive'
2022-09-13 22:21:05 +00:00
]
]
]);
}
/**
* 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' => [
'new' => 'New',
'applied' => 'Applied',
'refine' => 'Refine',
'approved' => 'Approved',
'archive' => 'Archive'
]
]
]);
}
}