Skip to content

9. How do exclude parameters from queries?

Selahattin edited this page Dec 3, 2015 · 1 revision

Example request: /api/users?name=john&token=xEaefk2325eoUt

If your table has not "token" column, you will see "Unknown column name 'token'" error. So, How do exclude "token" parameter or any parameter for the queries?

1. For globally:

If you want to exclude any parameter as globally, you should add this parameter into config/api-query-builder.php excludedParameters array.

Example:

// /config/api-query-builder.php

<?php 
return [
    
    'limit' => 15,
    'orderBy' => [
        [
            'column' => 'id',
            'direction' => 'desc'
        ]
    ],
    'excludedParameters' => ['token', 'otherParameter', 'anyParameter'],
];
?>

When you add it, these parameters ("token, otherParameter, anyParameter") will not be searched on table.


### 2. For Specific Query Builder

If you want to exclude any parameter for just specific query builder (eg: UserQueryBuilder), then you should add this parameter into "UserQueryBuilder" $excludedParameters property.

Example:

<?php

class UserQueryBuilder extends QueryBuilder 
{
  $excludedParameters = ['anyParameter', 'otherParameter'];
}
?>