1. Go to this page and download the library: Download winex01/backpack-filter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class EntityCrudController extends CrudController
{
use \Winex01\BackpackFilter\Http\Controllers\Operations\FilterOperation;
// method setup....
public function setupFilterOperation()
{
$this->crud->field([
'name' => 'status',
'label' => __('Status'),
'type' => 'select',
'options' => [
1 => 'Connected',
2 => 'Disconnected'
],
'wrapper' => [
'class' => 'form-group col-md-6'
]
]);
//
$this->crud->field([
'name' => 'date_range',
'label' => __('Date Range'),
'type' => 'date_range',
// although this is a custom field, you can still use the wrapper and attribute here
]);
}
public function setupListOperation()
{
// if you use this method closure, validation is automatically applied.
$this->filterQueries(function ($query) {
$status = request()->input('status');
$dates = request()->input('date_range');
if ($status) {
$query->where('status_id', $status);
}
if ($dates) {
$dates = explode('-', $dates);
//$query->where... your clause here or scope.
}
});
// some code here... add column etc...
}
public function filterValidations()
{
// If no access to filters, then don't proceed but don't show an error.
if (!$this->crud->hasAccess('filters')) {
return false;
}
// if you dont want to use validator and want to use request file, modify below, up to you.
$validationErrors = [];
// validator here.
if (!empty($validationErrors)) {
\Alert::error($validationErrors)->flash();
return redirect()->back();
}
return redirect()->back()->withInput(request()->input());
}
// crud controller
class UserCrudController extends CrudController
{
use \Winex01\BackpackFilter\Http\Controllers\Operations\ExportOperation;
// Optional: if you dont want to use the entity/export or user/export convention you can override the export route:
public function exportRoute()
{
return route('test.export');; // if you define a route here then it will use instead of the auto
}
// setup method...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.