187 lines
6.1 KiB
PHP
Executable File
187 lines
6.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Requests\DocumentRequest;
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController;
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
|
|
|
|
/**
|
|
* Class DocumentCrudController
|
|
* @package App\Http\Controllers\Admin
|
|
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
|
|
*/
|
|
class DocumentCrudController 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\Document::class);
|
|
CRUD::setRoute(config('backpack.base.route_prefix') . '/document');
|
|
CRUD::setEntityNameStrings('document', 'documents');
|
|
}
|
|
|
|
/**
|
|
* 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' => 'name',
|
|
'type' => 'text',
|
|
'label' => 'Name'
|
|
],
|
|
[
|
|
'name' => 'max_size',
|
|
'type' => 'number',
|
|
'label' => 'Max size (KBytes)',
|
|
'default' => 0
|
|
],
|
|
[
|
|
'name' => 'business',
|
|
'type' => 'radio',
|
|
'label' => 'Enterpreneurs',
|
|
'options' => [
|
|
1 => 'Yes',
|
|
0 => 'No'
|
|
]
|
|
],
|
|
[
|
|
'name' => 'company',
|
|
'type' => 'radio',
|
|
'label' => 'Companies',
|
|
'options' => [
|
|
1 => 'Yes',
|
|
0 => 'No'
|
|
]
|
|
],
|
|
[
|
|
'name' => 'all_country',
|
|
'type' => 'radio',
|
|
'label' => 'All countries',
|
|
'options' => [
|
|
1 => 'Yes',
|
|
0 => 'No'
|
|
]
|
|
],
|
|
[
|
|
'label' => "Document Countries",
|
|
'type' => 'select_multiple',
|
|
'name' => 'countries',
|
|
|
|
'entity' => 'countries',
|
|
'model' => "App\Models\Country",
|
|
'attribute' => 'name',
|
|
'pivot' => true,
|
|
|
|
'options' => (function ($query) {
|
|
return $query->orderBy('name', 'ASC')->get();
|
|
}),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Define what happens when the Create operation is loaded.
|
|
*
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-create
|
|
* @return void
|
|
*/
|
|
protected function setupCreateOperation()
|
|
{
|
|
CRUD::setValidation(DocumentRequest::class);
|
|
$this->crud->addFields([
|
|
[
|
|
'name' => 'name',
|
|
'type' => 'text',
|
|
'label' => 'Name'
|
|
],
|
|
[
|
|
'name' => 'description',
|
|
'type' => 'textarea',
|
|
'label' => 'Description'
|
|
],
|
|
[
|
|
'name' => 'max_size',
|
|
'type' => 'number',
|
|
'label' => 'Max size (KBytes)',
|
|
'default' => 0
|
|
],
|
|
[ // Checkbox
|
|
'name' => 'business',
|
|
'label' => 'Enterpreneurs',
|
|
'type' => 'checkbox'
|
|
],
|
|
[ // Checkbox
|
|
'name' => 'company',
|
|
'label' => 'Companies',
|
|
'type' => 'checkbox'
|
|
],
|
|
[ // Checkbox
|
|
'name' => 'all_country',
|
|
'label' => 'All countries',
|
|
'type' => 'checkbox'
|
|
],
|
|
// [ // SelectMultiple = n-n relationship (with pivot table)
|
|
// 'label' => "Document Groups",
|
|
// 'type' => 'select_multiple',
|
|
// 'name' => 'groups', // the method that defines the relationship in your Model
|
|
|
|
// // optional
|
|
// 'entity' => 'groups', // the method that defines the relationship in your Model
|
|
// 'model' => "App\Models\Documentgroup", // foreign key model
|
|
// 'attribute' => 'name', // foreign key attribute that is shown to user
|
|
// 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
|
|
|
|
// // also optional
|
|
// 'options' => (function ($query) {
|
|
// return $query->orderBy('name', 'ASC')->get();
|
|
// }), // force the related options to be a custom query, instead of all(); you can use this to filter the results show in the select
|
|
// ],
|
|
[
|
|
'label' => "Document Countries",
|
|
'type' => 'select2_multiple',
|
|
'name' => 'countries',
|
|
|
|
'entity' => 'countries',
|
|
'model' => "App\Models\Country",
|
|
'attribute' => 'name',
|
|
'pivot' => true,
|
|
|
|
'options' => (function ($query) {
|
|
return $query->orderBy('name', 'ASC')->get();
|
|
}),
|
|
],
|
|
[
|
|
'name' => 'max_size',
|
|
'type' => 'text',
|
|
'label' => 'Max size (KBytes)'
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Define what happens when the Update operation is loaded.
|
|
*
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-update
|
|
* @return void
|
|
*/
|
|
protected function setupUpdateOperation()
|
|
{
|
|
$this->setupCreateOperation();
|
|
}
|
|
}
|