Skip to content

Commit

Permalink
feat: added event triggers for create and update
Browse files Browse the repository at this point in the history
  • Loading branch information
craigAtCD committed May 30, 2022
1 parent 3b9e4cc commit 59dd8ef
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Events/UserCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Phpsa\FilamentAuthentication\Events;

use Illuminate\Queue\SerializesModels;

class UserCreated
{
use SerializesModels;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
28 changes: 28 additions & 0 deletions src/Events/UserUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Phpsa\FilamentAuthentication\Events;

use Illuminate\Queue\SerializesModels;

class UserUpdated
{
use SerializesModels;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
7 changes: 7 additions & 0 deletions src/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Phpsa\FilamentAuthentication\Events\UserCreated;

class CreateUser extends CreateRecord
{
public static function getResource(): string
{
return Config::get('filament-authentication.resources.UserResource');
}

protected function afterCreate(): void
{
Event::dispatch(new UserCreated($this->record));
}
}
7 changes: 7 additions & 0 deletions src/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Phpsa\FilamentAuthentication\Resources\UserResource\Pages;

use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Config;
use Filament\Resources\Pages\EditRecord;
use Phpsa\FilamentAuthentication\Events\UserUpdated;

class EditUser extends EditRecord
{
Expand All @@ -19,4 +21,9 @@ protected function mutateFormDataBeforeSave(array $data): array
}
return $data;
}

protected function afterSave(): void
{
Event::dispatch(new UserUpdated($this->record));
}
}

0 comments on commit 59dd8ef

Please sign in to comment.