Skip to content

Releases: BinarCode/laravel-restify

3.12.0

15 Jul 16:46
Compare
Choose a tag to compare

Added

  • Match by datetime
class PostRepository extends Repository
{
    public static $match = [
        'published_at' => RestifySearchable::MATCH_DATETIME,
    ];
}

Request:

GET: /restify-api/posts?published_at=2020-12-01
  • Match by array
class PostRepository extends Repository
{
    public static $match = [
        'published_at' => RestifySearchable::MATCH_ARRAY,
    ];
}

Request:

GET: /restify-api/posts?id=1,2,3

This will be converted to:

->whereIn('id', [1, 2, 3])
  • Negate a match
GET: /restify-api/posts?-id=1,2,3

This will return all posts where doesn't have the id in the [1,2,3] list.

You can apply - (negation) for every match:

GET: /restify-api/posts?-title="Some title"

3.11.0

10 Jul 08:05
499c008
Compare
Choose a tag to compare

Added

This is very wanted feature, for a long time.

  • Actions, an action performed to a bunch of models, or to a single model. Check it out

Before:

image

After:

image

3.10.0

03 Jul 14:36
214a3f1
Compare
Choose a tag to compare

Added

Bulk store

POST: restify-api/posts/bulk

Payload:

[ { "title": "Post title 1"}, { "title": "Post title 2"} ]

Bulk udpate

This is as well post. Just because using "POST" you can pass form data:

POST: restify-api/posts/bulk/update

Payload:

[ { "id":1, "title": "Post title 1"}, { "id": 2, "title": "Post title 2"} ]

3.9.0

02 Jul 12:42
555fa81
Compare
Choose a tag to compare

Force eager loading

However, Laravel Restify provides eager loading based on the query related property,
you may want to force eager load a relationship in terms of using it in fields, or whatever else:

// UserRepository.php

public static $with = ['posts'];

3.8.0

30 Jun 11:36
Compare
Choose a tag to compare

Added

  • RestResponse static index method, so you can return the same format for a custom paginator.
$paginator = User::query()->paginate(5);

$response = Binaryk\LaravelRestify\Controllers\RestResponse::index(
    $paginator
);

Changed

  • Signature of the resolveIndexMainMeta method, now it accept the paginatorMeta information:
public function resolveIndexMainMeta(RestifyRequest $request, Collection $items, array $paginationMeta): array

3.7.0

15 Jun 12:08
Compare
Choose a tag to compare

Index main meta

You can also override the main meta object for the index, not the one for per item:

public function resolveIndexMainMeta(RestifyRequest $request, Collection $items)
{
 $default = parent::resolveIndexMeta($request);
    return array_merge($default, [
        'next_payment_at' => $this->resource->current_payment_at->addMonth(),
    ]);
}

3.6.0

09 Jun 20:53
0a892da
Compare
Choose a tag to compare

Added

Ability to setup your own attachers. For example if you want to attach users to a role, and you don't want to use the default attach method. In this case you can override the attach method like this:

// RoleRepository.php

public function attachUsers(RestifyRequest $request, Repository $repository, Model $model)
    {
        ModelHasRole::create([
            'role_id' => $model->id,
            'model_type' => User::class,
            'model_id' => $request->get('users'),
        ]);

        return $this->response()->created();
    }

The URL used for attach will remain the same as for a normal attach:

'restify-api/roles/' . $role->id . '/attach/users'

3.5.1

24 May 16:17
Compare
Choose a tag to compare

Fixed

  • Handler HttpException returns now the correct code
  • HttpNotFound exception returns now the passed message

3.5.0

24 May 15:52
Compare
Choose a tag to compare

Added

  • Possibility to add custom middleware the repository level:
public static $middlewares = [
        PostAbortMiddleware::class,
];

or if you need RestifyRequest you can override the collecting method:

   public static function collectMiddlewares(RestifyRequest $request): ?Collection
    {
        if ($request->isStoreRequest()) {
            return collect([PostAbortMiddleware::class]);
        }
    }
  • Adapting profile endpoint to return attributes property.

3.4.1

23 May 18:03
c3afc33
Compare
Choose a tag to compare

Added

  • User full url for the avatar after updating avatar

Fixed

  • Validation for the email on profile update except current user