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

135 lines
4.3 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\BusinessRequest;
use App\Models\Account;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\Request;
/**
* Class BusinessCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class BusinessCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
// use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }
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()
{
if(!(backpack_user()->hasPermissionTo('clients'))){
$this->crud->denyAccess(['delete', 'update']);
}
CRUD::setModel(\App\Models\Business::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/business');
CRUD::setEntityNameStrings(trans('app.business.title'), trans('app.business.list_title'));
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
CRUD::addColumn([
'name' => 'name',
'type' => 'text',
'label' => trans('app.business.name')
]);
CRUD::addColumn([
'name' => 'surname',
'type' => 'text',
'label' => trans('app.business.surname')
]);
CRUD::addColumn([
'name' => 'patronomic_name',
'type' => 'text',
'label' => trans('app.business.patronomic_name')
]);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(BusinessRequest::class);
$this->crud->addFields([
[
'name' => 'name',
'label' => trans('app.business.name'),
'type' => 'text',
],
[
'name' => 'surname',
'label' => trans('app.business.surname'),
'type' => 'text',
],
[
'name' => 'patronomic_name',
'label' => trans('app.business.patronomic_name'),
'type' => 'text',
],
[
'name' => 'date_of_birth',
'label' => trans('app.business.date_of_birth'),
'type' => 'date',
],
[
'name' => 'birth_place',
'label' => trans('app.business.birth_place'),
'type' => 'text',
],
[
'name' => 'registration_address',
'label' => trans('app.business.registration_address'),
'type' => 'text',
],
[
'label' =>trans('app.business.citizenship'),
'type' => 'select',
'name' => 'citizenship', // the method that defines the relationship in your Model
'entity' => 'citizenship', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "App\Models\Country", // foreign key model
]
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}