laravel-restify

The fastest way to make a powerful JSON:API compatible Rest API with Laravel.

MIT License

Downloads
321.1K
Stars
600
Committers
20

Bot releases are visible (Hide)

laravel-restify - 3.16.0

Published by binaryk about 4 years ago

Added

Standalone actions

Sometimes you don't need to have an action with models. Let's say for example the authenticated user wants to disable his account. For this we have standalone actions:

// UserRepository

    public function actions(RestifyRequest $request)
    {
        return [
            DisableProfileAction::new()->standalone(),
        ];
    }

URI Key

Usually the URL for the action is make based on the action name. You can use your own URI key if you want:

class DisableProfileAction extends Action
{
    public static $uriKey = 'disable_profile';

    //...
}
laravel-restify - 3.15.0

Published by binaryk about 4 years ago

Added

  • mainQuery on repositories, now you can use this for show and index endpoints
  • Added Binaryk\LaravelRestify\Models\CreationAware interface. Now you can extend it, and you will take the control over the model saving
  • now you can add a single entity to related
laravel-restify - 3.14.0

Published by binaryk about 4 years ago

Added

  • Loading relationship from memory (eagers)
laravel-restify - 3.13.0

Published by binaryk about 4 years ago

Added

  • HasMany field
  • BelongsTo field
  • Custom callback for matching
  • Adding new validation support for Unique
  • Using UsersRepository for user profile
  • Adding prefixes for repositories routes

Fixes

  • Related now works with any page
laravel-restify - 3.12.2

Published by binaryk over 4 years ago

Patch

Fixing filter.

Added

  • booted method for repositories
laravel-restify - 3.12.1

Published by binaryk over 4 years ago

Added

Profile via User Repository

You can use the UserRepository (if you have one), to resolve the profile and perform the updates over the profile by using the UserProfile trait in your repository:

class UserRepository extends Repository
{
    use Binaryk\LaravelRestify\Repositories\UserProfile;
}

Checkout the documentation for more details.

laravel-restify - 3.12.0

Published by binaryk over 4 years ago

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"
laravel-restify - 3.11.0

Published by binaryk over 4 years ago

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

laravel-restify - 3.10.0

Published by binaryk over 4 years ago

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"} ]
laravel-restify - 3.9.0

Published by binaryk over 4 years ago

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'];
laravel-restify - 3.8.0

Published by binaryk over 4 years ago

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
laravel-restify - 3.7.0

Published by binaryk over 4 years ago

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(),
    ]);
}
laravel-restify - 3.6.0

Published by binaryk over 4 years ago

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'
laravel-restify - 3.5.1

Published by binaryk over 4 years ago

Fixed

  • Handler HttpException returns now the correct code
  • HttpNotFound exception returns now the passed message
laravel-restify - 3.5.0

Published by binaryk over 4 years ago

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.
laravel-restify - 3.4.1

Published by binaryk over 4 years ago

Added

  • User full url for the avatar after updating avatar

Fixed

  • Validation for the email on profile update except current user
laravel-restify - 3.4.0

Published by binaryk over 4 years ago

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}";
}
laravel-restify - 3.3.0

Published by binaryk over 4 years ago

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')

laravel-restify - 3.2.0

Published by binaryk over 4 years ago

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'));
laravel-restify - 3.1.0

Published by binaryk over 4 years ago

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,
        ]);
Package Rankings
Top 6.09% on Packagist.org
Related Projects