Skip to content

Commit

Permalink
Merge pull request #58 from daniel-de-wit/feature/register-extendability
Browse files Browse the repository at this point in the history
Improve extendability of the register mutation
  • Loading branch information
wimski authored Jun 21, 2021
2 parents 3413b74 + 910fbb5 commit 35b004f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/GraphQL/Mutations/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Laravel\Sanctum\Contracts\HasApiTokens;

Expand Down Expand Up @@ -48,9 +49,10 @@ public function __invoke($_, array $args): array
/** @var EloquentUserProvider $userProvider */
$userProvider = $this->createUserProvider();

$user = $userProvider->createModel();
$user->fill($this->getPropertiesFromArgs($args));
$user->save();
$user = $this->saveUser(
$userProvider->createModel(),
$this->getPropertiesFromArgs($args),
);

if ($user instanceof MustVerifyEmail) {
if (isset($args['verification_url'])) {
Expand All @@ -75,6 +77,20 @@ public function __invoke($_, array $args): array
];
}

/**
* @param Model $user
* @param array<string, mixed> $attributes
* @return Model
*/
protected function saveUser(Model $user, array $attributes): Model
{
$user
->fill($attributes)
->save();

return $user;
}

/**
* @param array<string, mixed> $args
* @return array<string, string>
Expand Down

0 comments on commit 35b004f

Please sign in to comment.