Skip to content

Releases: BinarCode/laravel-restify

3.8.0

30 Jun 11:36

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

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

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

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

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

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

3.4.0

23 May 17:51

Choose a tag to compare

Added

  • Profile endpoint GET:restify/profile
  • Update Profile endpoint PUT:restify/profile
  • Profile Avatar endpoint GET:restify/profile/avatar

You can customize the user avatar column by using:

Binaryk\LaravelRestify\Http\Requests\ProfileAvatarRequest::$userAvatarAttribute = 'avatar';

You can also customize the path to the file using:

Binaryk\LaravelRestify\Http\Requests\ProfileAvatarRequest::$path = 'avatars';

or if you need current request:

Binaryk\LaravelRestify\Http\Requests\ProfileAvatarRequest::$usingPath = function (RestifyRequest $request) {
 return "avatars/{$user->id}";
}

3.3.0

20 May 11:05
0491ae4

Choose a tag to compare

Added

  • Field label, so you can replace a field attribute:
Field::new('created_at')->label('sent_at')
  • Field can be setup as hidden:
Field::new('token')->hidden(); // this will not be visible 
  • Field can have append value, to append information like auth user, or any other relationships:
Field::new('user_id')->hidden()->append(auth()->user()->id); // this will not be visible, but will be stored
  • Related repositories no longer requires a viaRelationship query param, as it will get the default one from the main repository:
    Before:

axios.get('/restify/users?viaRelationship=users&viaRepositoryId=1&viaRepository=companies')

After:

axios.get('/restify/users?viaRepositoryId=1&viaRepository=companies')

3.2.0

19 May 21:56
5bf9fea

Choose a tag to compare

Added

  • Detach repository
  • Detach multiple repositories
 $users = $this->mockUsers(3);
        $company = factory(Company::class)->create();
        $company->users()->attach($users->pluck('id'));

        $usersFromCompany = $this->getJson('/restify-api/users?viaRepository=companies&viaRepositoryId=1&viaRelationship=users');
        $this->assertCount(3, $usersFromCompany->json('data'));

        $this->postJson('restify-api/companies/' . $company->id . '/detach/users', [
            'users' => [1, 2]
        ])
            ->assertStatus(204);

        $usersFromCompany = $this->getJson('/restify-api/users?viaRepository=companies&viaRepositoryId=1&viaRelationship=users');
        $this->assertCount(1, $usersFromCompany->json('data'));

3.1.0

19 May 21:31
a3118f4

Choose a tag to compare

Added

  • Attach related models to a model (check tests)
  • Attach multiple related model to a model
  • Attach extra information to the pivot
 $response = $this->postJson('restify-api/companies/' . $company->id . '/attach/users', [
            'users' => [1, 2],
            'is_admin' => true,
        ])
            ->assertStatus(201);

        $response->assertJsonFragment([
            'company_id' => '1',
            'user_id' => $user->id,
            'is_admin' => true,
        ]);