Skip to content

Conversation

@binaryk
Copy link
Collaborator

@binaryk binaryk commented Jun 9, 2020

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'

@binaryk binaryk merged commit 0a892da into 3.x Jun 9, 2020
@binaryk binaryk deleted the Attachers branch June 9, 2020 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants