Releases: BinarCode/laravel-restify
Releases · BinarCode/laravel-restify
3.8.0
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 thepaginatorMeta
information:
public function resolveIndexMainMeta(RestifyRequest $request, Collection $items, array $paginationMeta): array
3.7.0
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
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
3.5.0
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
3.4.0
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
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
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
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,
]);