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

155 lines
5.0 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\AccountRequest;
use App\Models\Business;
use App\Models\Company;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class AccountCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class AccountCrudController 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\Account::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/account');
CRUD::setEntityNameStrings('account', 'accounts');
$this->crud->addFilter([
'name' => 'type',
'type' => 'dropdown',
'label' => 'Type'
], [
'business' => 'business',
'company' => 'company'
], function ($value) { // if the filter is active
$this->crud->addClause('where', 'type', $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::column('type');
CRUD::addColumn([
'name' => 'profile',
'label' => 'Name',
'type' => 'profile_name'
]);
CRUD::column('legalization_number');
CRUD::column('expires_at');
CRUD::column('country');
$this->crud->addButtonFromModelFunction('line', 'preview_button', 'preview', 'beginning');
$this->crud->addButtonFromModelFunction('line', 'export_button', 'export_account', '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(AccountRequest::class);
$this->crud->addFields([
[
'name' => 'legalization_number',
'label' => 'Legalization number',
'type' => 'text',
'tab' => '#1. Legalization'
],
[
'name' => 'expires_at',
'label' => 'Expires at',
'type' => 'date',
'tab' => '#1. Legalization'
],
[
'name' => 'bank',
'label' => 'Bank',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'account_number' => 'Account number',
'account_date' => 'Account date',
'currency' => 'Currency',
'iban' => 'IBAN',
'bank_name' => 'Bank name',
'country' => 'Country'
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => '#2. Bank'
],
[
'name' => 'contacts',
'label' => 'Contacts',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'address' => 'Address',
'phone' => 'Phone',
'email' => 'Email',
'fax' => 'Fax'
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
'tab' => '#3. Contacts'
],
[
'name' => 'country_id',
'label' => 'Country',
'type' => 'select',
'entity' => 'country',
'model' => "App\Models\Country", // related model
'attribute' => 'name', // foreign key attribute that is shown to user
'tab' => '#4. Country'
],
]);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}