rxcod9/joy-voyager-datatable

filterRelationship

sanvolter opened this issue · 2 comments

Hi,

It's very interesting project. Are You going to finish it ?
Without working filters the usefulness of the solution is very limited.

protected function filterRelationship(
$query,
$keyword,
DataRow $row,
DataType $dataType,
Request $request
): void {
// @todo Not implemented yet.
}

@sanvolter
Meanwhile you can create an scope for the data row field and it will work as filter

PRs are welcome 🙏

Maybe it will be useful to someone:

protected function filterRelationship(
$query,
$keyword,
DataRow $row,
DataType $dataType,
Request $request
): void {

            $search_value = '%'.$keyword.'%';
            $search_filter = 'LIKE';
            $relationshipIds = [];
                if ($row->type == 'relationship' && isset($row->details) && $row->details->type == 'belongsTo'){
                        $relationshipIds = DB::table($row->details->table)
                            ->select($row->details->key, $row->details->label)
                            ->where($row->details->label, $search_filter, $search_value)
                            ->pluck($row->details->key)
                            ->toArray();
                }
                $query->whereIn($row->details->column,$relationshipIds);

}