-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.x] Update check for filtering column from include #70
Conversation
If we set: |
yes but imagine that we have hundred of field in the sub-property and that this author object is used in hundred of other classes this becomes a nightmare to maintain. |
Thank you very much for the contribution but I think this can be made more easier without whiteListFilteType. |
of course, but i didn't know how to make the checkFilterColumn find the correct class. |
Hmm... author is relationship we can grab class from relationship 🚀 |
oh ! i didn't know that (i'm pretty new to laravel) if you give me an hint to the documentation i'ld be happy to make the correct modification. (and now that i think about it, we could maybe handle both of the syntax, the |
I think this is can be more easy for example if we want to filter all columns of author we can do something like:
|
i also like your idea and i could also add it. |
Also |
So the list of possible values could be
|
When you set |
@gentritabazi01 normally everything is there now. i hope that everything will work correctly. |
Did you make tests locally for all cases ? |
Yes of course, but because we don't have unit tests i would gladly prefere that you also test it 😅 |
$nextColums = join('.', array_slice($parts, 1)); | ||
$baseClass = new $baseClassName(); | ||
$nextClass = method_exists($baseClass, $firstPart) ? get_class($baseClass->$firstPart()->getRelated()) : ''; | ||
// If the whiteListFilter contains a column with a star we want to bypass the check for the next part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put extra line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before line 320
.
```php | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class User extends Model | ||
{ | ||
use HasFactory; | ||
|
||
public function author() | ||
{ | ||
return $this->belongsTo(Author::class); | ||
} | ||
|
||
// List of all valid syntax for $whiteListFilter | ||
//public static $whiteListFilter = ['*']; | ||
//public static $whiteListFilter = ['id', 'title', 'author']; | ||
//public static $whiteListFilter = ['id', 'title', 'author.*']; | ||
|
||
} | ||
``` | ||
|
||
If the filter is `['*']` then all properties and sub-properties can be used for filtering. | ||
If the filter is `a list of model properties` then only the selected properties can be filtered. | ||
If some of the filter are a relationship then only the `$whiteListFilter` properties of the sub-property's model can be filtered. | ||
If some of the filter contains a `.*` the all sub-properties of the relationship model can be filtered (the `$whiteListFilter` is not used). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To much code here,
Can you update like this:
List of all valid syntax for $whiteListFilter
:
public static $whiteListFilter = ['*'];
public static $whiteListFilter = ['id', 'title', 'author'];
public static $whiteListFilter = ['id', 'title', 'author.*'];
If the filter is ['*']
then all properties and sub-properties can be used for filtering.
If the filter is a list of model properties
then only the selected properties can be filtered.
If some of the filter are a relationship then only the $whiteListFilter
properties of the sub-property's model can be filtered.
If some of the filter contains a .*
the all sub-properties of the relationship model can be filtered.
This pull request has been close since there has not been any recent activity. Please open a new pull request for related feature. |
if we try to use the filter method on a column based on an included properties like this :
the current implementation will crash because
author.name
won't be in the$whiteListFilter
.if we use this modification like this we can find a way to reuse properties :
The
checkFilterColumn
will check the first part of the $colum variables (author.name
=>author
) and then check the next part (name
=>name
) against theAuthor::class
Like this we can filter all properties and sub-properties.