The fastest way to make a powerful JSON:API compatible Rest API with Laravel.
MIT License
Bot releases are hidden (Show)
Published by binaryk 4 months ago
Starting from version 9.3.0, Laravel Restify introduces the ability to apply advanced filters using a POST request. This enhancement simplifies the process of sending complex filter payloads without the need for base64 encoding. Now, you can send the filters directly as JSON in the request body:
const filters = [
{
'key': 'ready-posts-filter',
'value': null,
}
];
const response = await axios.post(`api/restify/posts/apply-restify-advanced-filters`, { filters });
Published by binaryk 4 months ago
In some scenarios, you might want to send additional data beyond the standard key and value in your filter payload. For instance, you may need to specify an operator or a column to apply more complex filtering logic. Laravel Restify Advanced Filters provide a way to handle these additional payload fields using the $this->rest()
method.
Example Payload
Consider the following payload:
const filters = btoa(JSON.stringify([
{
'key': ValueFilter::uriKey(),
'value': 'Valid%',
'operator' => 'like',
'column' => 'description',
}
]));
const response = await axios.get(`api/restify/posts?filters=${filters}`);
In this payload, besides the standard key and value, we are also sending operator and column. The operator specifies the type of SQL operation, and the column specifies the database column to filter.
Using $this->rest()
to Access Additional Data
To handle these additional fields in your filter class, you need to ensure they are accessible via the $this->rest()
method. Here is how you can achieve that:
class ValueFilter extends AdvancedFilter
{
public function filter(RestifyRequest $request, Builder|Relation $query, $value)
{
$operator = $this->rest('operator');
$column = $this->rest('column');
$query->where($column, $operator, $value);
}
public function rules(Request $request): array
{
return [];
}
}
Published by binaryk 5 months ago
Restify allows individual caching at the policy level with specific configurations. To enable this, a contract Cacheable
must be implemented at the policy level, which enforces the use of the cache()
method.
class PostPolicy implements Cacheable
{
public function cache(): ?CarbonInterface
{
return now()->addMinutes();
}
The cache
method is expected to return a CarbonInterface
or null
. If null
is returned, the current policy will NOT
cached.
Published by binaryk 7 months ago
Published by binaryk 7 months ago
Published by binaryk 10 months ago
Published by binaryk 10 months ago
Published by binaryk 11 months ago
Published by binaryk about 1 year ago
Published by binaryk about 1 year ago
Published by binaryk about 1 year ago
Published by binaryk about 1 year ago
Published by binaryk over 1 year ago
Published by binaryk over 1 year ago
Published by binaryk over 1 year ago
Published by binaryk over 1 year ago
artisan restify:routes
commentPublished by binaryk over 1 year ago
thanks @dsindrilaru
Published by binaryk over 1 year ago
field('user_id')->canSeeWhen('can manage users'),
Published by binaryk over 1 year ago