Releases

9.3.1 8/20/2024

Fixed

  • fix(Bulk Update): Only Validate Data for Current Item in Loop #612

9.3.0 7/2/2024

Apply advanced filters via POST Request (Version 9.3.0+)

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 });

9.2.0 7/1/2024

Added

Handling Additional Payload Data in Advanced Filters

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 [];
    }
}

9.1.0 6/5/2024

Added

  • Ability to cache single policy #605

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.

9.0.0 4/1/2024

Added

  • Add support for Laravel 11 (#602)

8.4.0 4/1/2024

Added

  • Add support for Laravel 11 (#602)

8.3.2 12/30/2023

Fixed

  • Restifyjs setup without auth middleware

8.3.1 12/30/2023

8.3.0 11/22/2023

Added

  • Support searching string with single quotes in them #592

8.2.0 9/7/2023

Added

  • Added natural sort filter #586

Fixed

  • fix: rules method overrides already defined rules #575
  • Cleanup faker from cmd construct #580

8.1.5 9/7/2023

Fixed

  • Fixed accept string in filters #585

8.1.3 9/7/2023

Fixed

  • Fixed type for resolver #584

8.1.2 9/7/2023

Fixed

  • sortable filter update #583

8.1.1 6/16/2023

Fixed

  • change the route name

8.0.1 4/14/2023

Fixed

  • docs for getters #554

8.0.0 4/6/2023

Added

  • Support for Laravel 10 #540
  • Introduces a new option to publish specific auth actions #551
  • Take actionable fields into account when calling patch method #547
  • Custom namespaces support #549
  • New artisan restify:routes comment
  • Updated the documentation https://restify.binarcode.com/
  • 💯 - 💯 - 💯 - 💯

Improved

  • Larastan specs

7.11.0 3/16/2023

Added

  • Support for actionable fields on PATCH method #547

thanks @dsindrilaru

7.10.11 2/12/2023

Added

  • Now you can use the permission name for the field see authorization:
field('user_id')->canSeeWhen('can manage users'),

7.10.4 2/11/2023

Fixed

  • Do not display hidden pivots.

7.10.3 2/11/2023

Fixed

  • fix: do not filter belongs to many fields

7.10.2 2/4/2023

Fixed

7.10.1 2/4/2023

Fixed

  • Show the full path for the file when suggesting OpenAI solution.

7.10.0 2/4/2023

Inspired and thanks to Marcel for the article: https://beyondco.de/blog/ai-powered-error-solutions-for-laravel

Generate solution

Restify can generate an AI based solution to your problem. In order to enable that you need to extend the App\Exceptions\Handler with the Binaryk\LaravelRestify\Exceptions\RestifyHandler:

use Binaryk\LaravelRestify\Exceptions\RestifyHandler;
use Throwable;

class Handler extends RestifyHandler
{
    //...
}
This feature is only enabled when the `app.debug` is set to `true`.

This feature is using the openai-php/laravel, you should also publish the config file:

php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"

and set the OPENAI_API_KEY in the .env file.

The OpenAI key can be obtained from here.

Now the solution to your problems will automatically appear in the response:

{
    "restify-solution": "Line 67 in DocumentRepository.php file has an error because the method `resolveUsingFullPath()` is not defined. The code should look like this:\n```\n->resolveUsingTemporaryUrl($request->boolean('temporary'))\n```\n",
    "message": "Call to undefined method Binaryk\\LaravelRestify\\Fields\\File::resolveUsingFullPath()",
    "exception": "Error",
    "file": "/Users/eduardlupacescu/Sites/binarcode/erp/app/Restify/DocumentRepository.php",
    "line": 67,
    "trace": [
...
}

Disable solution

If you want to disable the solution feature you can set the restify.ai_solution to false in the config/restify.php file so Restify will not call the OpenAI API even you extended the exception handler. This might be useful in automated tests or other environments:

// config/restify.php
'ai_solutions' => true,

7.9.0 2/3/2023

Added

Customizing File Display

By default, Restify will display the file's stored path name. However, you may customize this behavior.

Displaying temporary url

For disks such as S3, you may instruct Restify to display a temporary URL to the file instead of the stored path name:

  field('path')
      ->file()
      ->path("documents/".Auth::id())
      ->resolveUsingTemporaryUrl()
      ->disk('s3'),

The resolveUsingTemporaryUrl accepts 3 arguments:

  • $resolveTemporaryUrl - a boolean to determine if the temporary url should be resolved. Defaults to true.

  • $expiration - A CarbonInterface to determine the time before the URL expires. Defaults to 5 minutes.

  • $options - An array of options to pass to the temporaryUrl method of the Illuminate\Contracts\Filesystem\Filesystem implementation. Defaults to an empty array.

Displaying full url

For disks such as public, you may instruct Restify to display a full URL to the file instead of the stored path name:

  field('path')
      ->file()
      ->path("documents/".Auth::id())
      ->resolveUsingFullUrl()
      ->disk('public'),

Fixed

  • fix: fixing dynamic user class

7.8.0 1/17/2023

Added

  • Now you can add a placeholder to the filter, so it renders on the frontend
'title' => MatchFilter::make()
                ->setDescription('Sort by title')
                ->setPlaceholder('-title')
                ->setType('string')

When we read match filters using: `/api/restify/posts/filters?only=matches` we will get:

[
      "type" => "string"
      "advanced" => false
      "title" => "Title"
      "description" => "Sort by title"
      "placeholder" => "-title"
      "column" => "title"
      "key" => "matches"
 ]

Fixed

  • Tests (thanks @arthurkirkosa)

7.7.2 1/13/2023

Fixed

  • Profile request class

7.7.1 11/22/2022

Fixed

  • Remove Email Exist validation #518

7.7.0 9/17/2022

You can also sync your BelongsToMany field. Say you have to sync permissions to a role. You can do it like this:

POST: api/restify/roles/1/sync/permissions

Payload:

{
  "permissions": [1, 2]
}

Under the hood this will call the sync method on the BelongsToMany relationship:

// $role of the id 1

$role->permissions()->sync($request->input('permissions'));

Authorize sync

You can define a policy method syncPermissions. The name should start with sync and suffix with the plural CamelCase name of the model's relationship name:

// RolePolicy.php

public function syncPermissions(User $authenticatedUser, Company $company, Collection $keys): bool
{ 
    // $keys are the primary keys of the related model (permissions in our case) Restify is trying to `sync`
}

7.6.3 9/16/2022

Fixed

  • The rest method will consider the meta information for the rest helper: rest($user)->indexMeta(['token' => $token])