The fastest way to make a powerful JSON:API compatible Rest API with Laravel.
MIT License
Bot releases are hidden (Show)
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
Inspired and thanks to Marcel for the article: https://beyondco.de/blog/ai-powered-error-solutions-for-laravel
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 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": [
...
}
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,
Published by binaryk over 1 year ago
By default, Restify will display the file's stored path name. However, you may customize this behavior.
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.
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'),
Published by binaryk almost 2 years ago
'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"
]
Published by binaryk almost 2 years ago
Published by binaryk almost 2 years ago
Published by binaryk about 2 years ago
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'));
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`
}
Published by binaryk about 2 years ago
rest($user)->indexMeta(['token' => $token])
Published by binaryk about 2 years ago
Inherited https://github.com/BinarCode/laravel-restify/releases/tag/6.12.2
Published by binaryk about 2 years ago
Published by binaryk about 2 years ago
policyMeta
method is now protected at the repository level (it could be used to override the policy information for the show and index methods.RelatedDto
as a singleton in a test environment (this causes issues when trying to make few relationship requests to the same repository in the same test)action
, route
and getters
).Published by binaryk about 2 years ago
Published by binaryk about 2 years ago
Published by binaryk about 2 years ago
Repository::route(
method has a new signature, it accepts the action
as well now.Published by binaryk about 2 years ago
Published by binaryk about 2 years ago
Published by binaryk about 2 years ago
This will enable policies to be cached by adding the configuration:
'cache' => [
/*
| Specify the cache configuration for the resources policies.
| When enabled, methods from the policy will be cached for the active user.
*/
'policies' => [
'enabled' => true,
/*
| ttl in seconds
*/
'ttl' => 5 * 60,
],
],
Published by binaryk about 2 years ago
YourRepository::partialMock()
for the index request, previously it ran into the mock state and didn't update the second resources in tests.$eagerState
repository property is now private, and it is of type null|string
because it holds the parent repository that renders it.