-
-
Notifications
You must be signed in to change notification settings - Fork 855
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1374 from suraj-webkul/datagrid-dropdown-searchab…
…le-filter datagrid searchable dropdown.
- Loading branch information
Showing
7 changed files
with
315 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/Webkul/Admin/src/Http/Controllers/DataGridController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Webkul\Admin\Http\Controllers; | ||
|
||
use Illuminate\Support\Facades\Crypt; | ||
|
||
class DataGridController extends Controller | ||
{ | ||
/** | ||
* Look up. | ||
*/ | ||
public function lookUp() | ||
{ | ||
/** | ||
* Validation for parameters. | ||
*/ | ||
$params = $this->validate(request(), [ | ||
'datagrid_id' => ['required'], | ||
'column' => ['required'], | ||
'search' => ['required', 'min:2'], | ||
]); | ||
|
||
/** | ||
* Preparing the datagrid instance and only columns. | ||
*/ | ||
$datagrid = app(Crypt::decryptString($params['datagrid_id'])); | ||
$datagrid->prepareColumns(); | ||
|
||
/** | ||
* Finding the first column from the collection. | ||
*/ | ||
$column = collect($datagrid->getColumns())->map(fn ($column) => $column->toArray())->where('index', $params['column'])->firstOrFail(); | ||
|
||
/** | ||
* Fetching on the basis of column options. | ||
*/ | ||
return app($column['filterable_options']['repository']) | ||
->select([$column['filterable_options']['column']['label'].' as label', $column['filterable_options']['column']['value'].' as value']) | ||
->where($column['filterable_options']['column']['label'], 'LIKE', '%'.$params['search'].'%') | ||
->get(); | ||
} | ||
} |
Oops, something went wrong.