thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.77k stars 2.67k forks source link

Fix server side relationship search #5754

Open samiksengupta opened 1 year ago

samiksengupta commented 1 year ago

This fixes the issue with Voyager's server side searching.

This potentially fixes #5645 #5635 #5433 #5412

This issue can be recreated by enabling Server-side Pagination in BREAD and then having a relationship field.

server-side

relationship

Now upon searching the relationship field in browse view, an exception occurs.

searching-role

exception

This fixes fixes duplicate filter field occurance and enables multiple relationship fields sharing same reference column

This also fixes the duplicate filter dropdown entries when there is a non-relation field sharing the same name with a relationship reference column name in the same BREAD.

bread-fields-duplicate

search-keys-repeats

Note that this will not affect multiple relation fields in a BREAD sharing the same relationship reference column name (but different display column for instance).

This allows use of custom relationship methods in eloquent models

If you are using a custom relationship method in your eloquent model, you can mention that method name in Relationship Details as long as you have specified your model in BREAD.

public function group()
{
    return $this->belongsTo(\TCG\Voyager\Facades\Voyager::modelClass('Role'), 'role_id');
}

customize-model

custom-relation

If a name is not specified, the relationship method name will be determined from the model name.

pckz commented 10 months ago

awesome work! thanks @samiksengupta
please @eclairAB review this PR 🙏