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

165 lines
6.2 KiB
PHP
Executable File

<?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;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* 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',
'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()
{
$this->crud->addColumns([
[
'name' => 'profile',
'type' => 'account_profile_name',
'label' => 'Account',
],
[ // 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',
],
[
'name' => 'state',
'label' => 'State',
'type' => 'badge',
],
[
'name' => 'created_at',
]
]);
}
/**
* 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([
// [
// 'name' => 'account_id',
// 'type' => 'custom_select_account',
// 'label' => 'Account',
// 'entity' => 'account',
// 'model' => "App\Models\Business",
// 'model_2' => "App\Models\Company",
// 'attribute_business_1' => 'name',
// 'attribute_business_2' => 'surname',
// 'attribute_2' => 'name'
// ],
[ // 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',
],
[
'name' => 'state',
'label' => 'State',
'type' => 'select_from_array',
'options' => [
'new' => 'new',
'applied' => 'applied',
'approved' => 'approved',
'archive' => 'archive'
]
]
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}