PHP Class EloquentFilter\ModelFilter

Afficher le fichier Open project: tucker-eric/eloquentfilter

Méthodes publiques

Свойство Type Description
$relations array Related Models that have ModelFilters as well as the method on the ModelFilter As [relatedModel => [input_key1, input_key2]].

Protected Properties

Свойство Type Description
$allRelations array Container for all relations (local and related ModelFilters).
$drop_id boolean Drop _id from the end of input keys when referencing methods.
$input array Array of input to filter.
$localRelatedFilters array (This allows us to not be required to define a filter for the related models).
$query Illuminate\Database\Eloquent\Builder
$relationsEnabled boolean This is to be able to bypass relations if we are filtering a joined table.

Méthodes publiques

Méthode Description
__call ( $method, $args ) Handle calling methods on the query object.
__construct ( $query, array $input = [], boolean $relationsEnabled = true ) ModelFilter constructor.
addRelated ( $relation, Closure $closure ) Locally defines a relation filter method that will be called in the context of the related model.
callRelatedLocalSetup ( $related, $query )
disableRelations ( ) Disable querying relations (Mainly for joined tables as the related model isn't queried).
dropIdSuffix ( null $bool = null ) : boolean Set to drop _id from input. Mainly for testing.
enableRelations ( ) Enable querying relations.
filterInput ( ) Filter with input array.
filterJoinedRelation ( $related ) Run the filter on models that already have their tables joined.
filterRelations ( ) Filter relationships defined in $this->relations array.
filterUnjoinedRelation ( $related ) Filters by a relationship that isn't joined by using that relation's ModelFilter.
getAllRelations ( ) : array Returns all local relations and relations requiring other Model's Filter's.
getFilterMethod ( $key ) : string
getJoinedTables ( ) : array Gets all the joined tables.
getLocalRelation ( string $related ) : array
getRelatedFilter ( $relation ) : mixed Get the model filter of a related model.
getRelatedFilterInput ( $related ) : array Get input to pass to a related Model's Filter.
getRelatedModel ( $relation ) : Model Get an empty instance of a related model.
getRelatedTable ( $relation ) : string Get the table name from a relationship.
getRelationConstraints ( string $relation ) : array Get all input to pass through related filters and local closures as an array.
handle ( ) : Builder Handle all filters.
input ( null $key = null, null $default = null ) : array | mixed | null Retrieve input by key or all input as array.
push ( $key, null $value = null ) Add values to filter by if called in setup().
related ( $relation, $column, null $operator = null, null $value = null, string $boolean = 'and' ) Add a where constraint to a relationship.
relationIsFilterable ( $relation ) : boolean Check to see if there is input or locally defined methods for the given relation.
relationIsJoined ( $relation ) : boolean Checks if the relation to filter's table is already joined.
relationIsLocal ( $related ) : boolean Checks to see if there are locally defined relations to filter.
relationUsesFilter ( $related ) : boolean Checks if there is input that should be passed to a related Model Filter.
relationsEnabled ( ) : boolean Checks if filtering by relations is enabled.
removeEmptyInput ( array $input ) : array Remove empty strings from the input array.

Method Details

__call() public méthode

Handle calling methods on the query object.
public __call ( $method, $args )
$method
$args

__construct() public méthode

ModelFilter constructor.
public __construct ( $query, array $input = [], boolean $relationsEnabled = true )
$query
$input array
$relationsEnabled boolean

addRelated() public méthode

Locally defines a relation filter method that will be called in the context of the related model.
public addRelated ( $relation, Closure $closure )
$relation
$closure Closure

callRelatedLocalSetup() public méthode

public callRelatedLocalSetup ( $related, $query )

disableRelations() public méthode

Disable querying relations (Mainly for joined tables as the related model isn't queried).
public disableRelations ( )

dropIdSuffix() public méthode

Set to drop _id from input. Mainly for testing.
public dropIdSuffix ( null $bool = null ) : boolean
$bool null
Résultat boolean

enableRelations() public méthode

Enable querying relations.
public enableRelations ( )

filterInput() public méthode

Filter with input array.
public filterInput ( )

filterJoinedRelation() public méthode

Run the filter on models that already have their tables joined.
public filterJoinedRelation ( $related )
$related

filterRelations() public méthode

Filter relationships defined in $this->relations array.
public filterRelations ( )

filterUnjoinedRelation() public méthode

Filters by a relationship that isn't joined by using that relation's ModelFilter.
public filterUnjoinedRelation ( $related )
$related

getAllRelations() public méthode

Returns all local relations and relations requiring other Model's Filter's.
public getAllRelations ( ) : array
Résultat array

getFilterMethod() public méthode

public getFilterMethod ( $key ) : string
$key
Résultat string

getJoinedTables() public méthode

Gets all the joined tables.
public getJoinedTables ( ) : array
Résultat array

getLocalRelation() public méthode

public getLocalRelation ( string $related ) : array
$related string
Résultat array

getRelatedFilter() public méthode

Get the model filter of a related model.
public getRelatedFilter ( $relation ) : mixed
$relation
Résultat mixed

getRelatedFilterInput() public méthode

Get input to pass to a related Model's Filter.
public getRelatedFilterInput ( $related ) : array
$related
Résultat array

getRelatedModel() public méthode

Get an empty instance of a related model.
public getRelatedModel ( $relation ) : Model
$relation
Résultat Illuminate\Database\Eloquent\Model

getRelatedTable() public méthode

Get the table name from a relationship.
public getRelatedTable ( $relation ) : string
$relation
Résultat string

getRelationConstraints() public méthode

Get all input to pass through related filters and local closures as an array.
public getRelationConstraints ( string $relation ) : array
$relation string
Résultat array

handle() public méthode

Handle all filters.
public handle ( ) : Builder
Résultat Illuminate\Database\Eloquent\Builder

input() public méthode

Retrieve input by key or all input as array.
public input ( null $key = null, null $default = null ) : array | mixed | null
$key null
$default null
Résultat array | mixed | null

push() public méthode

Will ONLY filter relations if called on additional method.
public push ( $key, null $value = null )
$key
$value null

relationIsFilterable() public méthode

Check to see if there is input or locally defined methods for the given relation.
public relationIsFilterable ( $relation ) : boolean
$relation
Résultat boolean

relationIsJoined() public méthode

Checks if the relation to filter's table is already joined.
public relationIsJoined ( $relation ) : boolean
$relation
Résultat boolean

relationIsLocal() public méthode

Checks to see if there are locally defined relations to filter.
public relationIsLocal ( $related ) : boolean
$related
Résultat boolean

relationUsesFilter() public méthode

Checks if there is input that should be passed to a related Model Filter.
public relationUsesFilter ( $related ) : boolean
$related
Résultat boolean

relationsEnabled() public méthode

Checks if filtering by relations is enabled.
public relationsEnabled ( ) : boolean
Résultat boolean

removeEmptyInput() public méthode

Remove empty strings from the input array.
public removeEmptyInput ( array $input ) : array
$input array
Résultat array

Property Details

$allRelations protected_oe property

Container for all relations (local and related ModelFilters).
protected array $allRelations
Résultat array

$drop_id protected_oe property

Drop _id from the end of input keys when referencing methods.
protected bool $drop_id
Résultat boolean

$input protected_oe property

Array of input to filter.
protected array $input
Résultat array

$localRelatedFilters protected_oe property

(This allows us to not be required to define a filter for the related models).
protected array $localRelatedFilters
Résultat array

$query protected_oe property

protected Builder,Illuminate\Database\Eloquent $query
Résultat Illuminate\Database\Eloquent\Builder

$relations public_oe property

Related Models that have ModelFilters as well as the method on the ModelFilter As [relatedModel => [input_key1, input_key2]].
public array $relations
Résultat array

$relationsEnabled protected_oe property

This is to be able to bypass relations if we are filtering a joined table.
protected bool $relationsEnabled
Résultat boolean