You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose is so that we can search for a foreign table's field e.g. name instead of only being able to filter by ID as the user might not know the ID.
I was able to modify ResourceRequest.php with the code below,
// update in ResourceRequest.phppublicfunctiongetModelPaginationList()
{
$builder = $this->model()
->with($this->resource()->with())
->filters()
->filtersApply($this->resource()->filters());
foreach (collect($this->resource()->columns()) as$column) {
$callback = $column->queryClosure; // also need to modify TD.php to support queryClosureif (!is_null($callback)) {
$filters = $this->request->all('filter');
$key = $column->column;
if (Arr::exists($filters, $key)) {
$term = $filters[$key];
$builder = $callback($term, $builder);
}
}
}
return$builder->paginate($this->resource()->perPage());
}
// add to TD.php/** * @var Closure|null */public$queryClosure;
publicfunctionquery(Closure$queryClosure)
{
$this->queryClosure = $queryClosure;
return$this;
}
Is there a better approach to make searching by foreign table field easier?
The text was updated successfully, but these errors were encountered:
Hi,
I would like to propose being able to write code like below:
The purpose is so that we can search for a foreign table's field e.g. name instead of only being able to filter by ID as the user might not know the ID.
I was able to modify
ResourceRequest.php
with the code below,Is there a better approach to make searching by foreign table field easier?
The text was updated successfully, but these errors were encountered: