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

213 lines
7.5 KiB
PHP
Raw Normal View History

<?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()
{
CRUD::setModel(\App\Models\Business::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/business');
CRUD::setEntityNameStrings('business', 'businesses');
}
/**
* 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' => 'personal',
'type' => 'json',
'label' => 'Personal'
]);
CRUD::addColumn([
'name' => 'document',
'type' => 'json',
'label' => 'Document'
]);
CRUD::addColumn([
'name' => 'job',
'type' => 'json',
'label' => 'Job'
]);
/**
* 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' => 'personal',
'label' => 'Personal',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'surname' => 'Surname',
'patronomic_name' => 'Patronomic name',
'date_of_birth' => 'Date of birth',
'birth_place' => 'Birth place',
'citizenship_id' => 'Citizenship ID',
'registration_address' => 'Registration address'
],
'max' => 15,
'min' => 0,
],
[
'name' => 'document',
'label' => 'Document',
'type' => 'table',
'entity_singular' => 'option',
'columns' => [
'doc_name' => 'Doc name',
'doc_series' => 'Doc series',
'doc_number' => 'Doc number',
'doc_date' => 'Doc date',
'doc_given_by' => 'Doc given by'
],
'max' => 15,
'min' => 0,
],
[
'name' => 'job',
'label' => 'Job',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'work_place' => 'Work place',
'position' => 'Position',
'business_type' => 'Business type',
'licenses' => 'Licenses',
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
2022-07-15 05:44:52 +00:00
],
[
'label' => "profile",
'type' => 'select',
'name' => 'account.id', // the method that defines the relationship in your Model
'entity' => 'account', // the method that defines the relationship in your Model
'attribute' => 'id', // foreign key attribute that is shown to user
'model' => "App\Models\Account", // foreign key model
]
]);
2022-07-15 05:44:52 +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(BusinessRequest::class);
$this->crud->addFields([
[
'name' => 'personal',
'label' => 'Personal',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'name' => 'Name',
'surname' => 'Surname',
'patronomic_name' => 'Patronomic name',
'date_of_birth' => 'Date of birth',
'birth_place' => 'Birth place',
'citizenship_id' => 'Citizenship ID',
'registration_address' => 'Registration address'
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
],
[
'name' => 'document',
'label' => 'Document',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'doc_name' => 'Doc name',
'doc_series' => 'Doc series',
'doc_number' => 'Doc number',
'doc_date' => 'Doc date',
'doc_given_by' => 'Doc given by'
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
],
[
'name' => 'job',
'label' => 'Job',
'type' => 'table',
'entity_singular' => 'option', // used on the "Add X" button
'columns' => [
'work_place' => 'Work place',
'position' => 'Position',
'business_type' => 'Business type',
'licenses' => 'Licenses',
],
'max' => 15, // maximum rows allowed in the table
'min' => 0, // minimum rows allowed in the table
],
]);
}
public function store()
{
$data = $this->crud->getRequest()->all();
$profile_id = $data['profile']['profile_id'];
$this->crud->getRequest()->request->remove('profile');
$response = $this->traitStore();
$current_id = $this->data['entry']['id'];
$account = Account::find($profile_id);
$account->profileable_id = $current_id;
$account->profileable_type = 'App\Models\Business';
$account->save();
return $response;
}
}