From 7d906b7f976d88920e292dabe41cc9f4c3ff38e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 5 Jul 2023 12:16:25 +0300 Subject: [PATCH] Added User Invitation created_by and created_from columns.. --- app/Jobs/Auth/CreateInvitation.php | 5 +++++ app/Models/Auth/UserInvitation.php | 2 +- database/migrations/2023_06_22_000000_core_v3016.php | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Auth/CreateInvitation.php b/app/Jobs/Auth/CreateInvitation.php index 10affdbf9..2dd300fb9 100644 --- a/app/Jobs/Auth/CreateInvitation.php +++ b/app/Jobs/Auth/CreateInvitation.php @@ -5,12 +5,15 @@ namespace App\Jobs\Auth; use App\Abstracts\Job; use App\Models\Auth\UserInvitation; use App\Notifications\Auth\Invitation as Notification; +use App\Traits\Sources; use Exception; use Illuminate\Support\Str; use Symfony\Component\Mailer\Exception\TransportException; class CreateInvitation extends Job { + use Sources; + protected $invitation; protected $user; @@ -32,6 +35,8 @@ class CreateInvitation extends Job $this->invitation = UserInvitation::create([ 'user_id' => $this->user->id, 'token' => (string) Str::uuid(), + 'created_by' => user_id(), + 'created_from' => $this->getSourceName(request()), ]); $notification = new Notification($this->invitation); diff --git a/app/Models/Auth/UserInvitation.php b/app/Models/Auth/UserInvitation.php index 2b8a85b23..cba5a1073 100644 --- a/app/Models/Auth/UserInvitation.php +++ b/app/Models/Auth/UserInvitation.php @@ -20,7 +20,7 @@ class UserInvitation extends Model * * @var string[] */ - protected $fillable = ['user_id', 'token']; + protected $fillable = ['user_id', 'token', 'created_from', 'created_by']; public function user() { diff --git a/database/migrations/2023_06_22_000000_core_v3016.php b/database/migrations/2023_06_22_000000_core_v3016.php index 1f19dc6fa..6c12bd1aa 100644 --- a/database/migrations/2023_06_22_000000_core_v3016.php +++ b/database/migrations/2023_06_22_000000_core_v3016.php @@ -26,6 +26,12 @@ return new class extends Migration $table->unique(['company_id', 'key', 'deleted_at']); }); + + // User Invitations + Schema::table('user_invitations', function (Blueprint $table) { + $table->unsignedInteger('created_by')->nullable()->after('token'); + $table->string('created_from', 100)->nullable()->after('token'); + }); } /** @@ -48,5 +54,11 @@ return new class extends Migration $table->unique(['company_id', 'key']); }); + + // User Invitations + Schema::table('user_invitations', function (Blueprint $table) { + $table->dropColumn('created_by'); + $table->dropColumn('created_from'); + }); } };