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.php
public function getModelPaginationList()
{
$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 queryClosure
if (!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;
public function query(Closure $queryClosure)
{
$this->queryClosure = $queryClosure;
return $this;
}
Is there a better approach to make searching by foreign table field easier?
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?