hasPermissionTo('applications'))){ $this->crud->denyAccess(['delete', 'update']); } CRUD::setModel(Application::class); CRUD::setRoute(config('backpack.base.route_prefix') . '/application'); CRUD::setEntityNameStrings('application', trans('app.application.list_title')); Application::updating(function($entry) { $entry->modified_by = backpack_user()->email; }); $this->crud->addFilter([ 'name' => 'state', 'type' => 'dropdown', 'label' => trans('app.application.state') ], [ 'new' => trans('app.application.new'), // 'applied' => trans('app.application.applied'), 'accepted' => trans('app.application.accepted'), 'refine' => trans('app.application.refine'), 'approved' => trans('app.application.approved'), 'archive' => trans('app.application.archived') ], function ($value) { // if the filter is active $this->crud->addClause('where', 'state', $value); }); $this->crud->addFilter([ 'type' => 'date_range', 'name' => 'from_to', 'label' => trans('app.application.date_filter'), ], 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'); }); $this->crud->addFilter([ 'type' => 'text', 'name' => 'accepted_by', 'label' => trans('app.last_updates.accepted_by'), ], false, function ($value) { $this->crud->addClause('where', 'accepted_by', 'LIKE', '%' . $value . '%'); }); } /** * 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->addClause('where', 'state', '!=', 'new'); $this->crud->addColumns([ [ 'name' => 'profile', 'type' => 'account_profile_name', 'label' => trans('app.application.account'), ], [ // SelectMultiple = n-n relationship (with pivot table) 'label' => trans('app.application.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' => trans('app.application.leg_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' => trans('app.application.expires_at'), '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' => trans('app.application.state'), 'type' => 'badge', ], [ 'name' => 'accepted_by', 'label' => trans('app.last_updates.accepted_by'), 'type' => 'text', ], [ 'name' => 'created_at', 'label' => trans('app.application.created_at'), ] ]); $this->crud->addButtonFromModelFunction('line', 'preview_button', 'preview', 'beginning'); // $this->crud->addButtonFromModelFunction('line', 'accept_button', 'accept', 'beginning'); } public function accept($id){ $entry = Application::findOrfail($id); $entry->accepted_by = backpack_user()->name; $entry->state = 'accepted'; $entry->accepted_date = Carbon::now(); $entry->save(); return redirect()->back(); } /** * 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([ // [ // SelectMultiple = n-n relationship (with pivot table) // 'label' => trans('app.application.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' => trans('app.application.state'), // 'type' => 'select_from_array', // 'options' => [ // 'new' => trans('app.application.new'), // 'applied' => trans('app.application.applied'), // 'refine' => trans('app.application.refine'), // 'approved' => trans('app.application.approved'), // 'archive' => trans('app.application.archived') // ] // ] // ]); // } /** * Define what happens when the Update operation is loaded. * * @see https://backpackforlaravel.com/docs/crud-operation-update * @return void */ // protected function setupUpdateOperation() // { // CRUD::setValidation(ApplicationRequest::class); // $this->crud->addFields([ // [ // 'name' => 'state', // 'label' => 'State', // 'type' => 'select_from_array', // 'options' => [ // 'new' => trans('app.application.new'), // 'applied' => trans('app.application.applied'), // 'refine' => trans('app.application.refine'), // 'approved' => trans('app.application.approved'), // 'archive' => trans('app.application.archived') // ] // ] // ]); // } }