Added User Invitation created_by and created_from columns..

This commit is contained in:
Cüneyt Şentürk 2023-07-05 12:16:25 +03:00
parent 2469bc2c09
commit 7d906b7f97
3 changed files with 18 additions and 1 deletions

View File

@ -5,12 +5,15 @@ namespace App\Jobs\Auth;
use App\Abstracts\Job; use App\Abstracts\Job;
use App\Models\Auth\UserInvitation; use App\Models\Auth\UserInvitation;
use App\Notifications\Auth\Invitation as Notification; use App\Notifications\Auth\Invitation as Notification;
use App\Traits\Sources;
use Exception; use Exception;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Symfony\Component\Mailer\Exception\TransportException; use Symfony\Component\Mailer\Exception\TransportException;
class CreateInvitation extends Job class CreateInvitation extends Job
{ {
use Sources;
protected $invitation; protected $invitation;
protected $user; protected $user;
@ -32,6 +35,8 @@ class CreateInvitation extends Job
$this->invitation = UserInvitation::create([ $this->invitation = UserInvitation::create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'token' => (string) Str::uuid(), 'token' => (string) Str::uuid(),
'created_by' => user_id(),
'created_from' => $this->getSourceName(request()),
]); ]);
$notification = new Notification($this->invitation); $notification = new Notification($this->invitation);

View File

@ -20,7 +20,7 @@ class UserInvitation extends Model
* *
* @var string[] * @var string[]
*/ */
protected $fillable = ['user_id', 'token']; protected $fillable = ['user_id', 'token', 'created_from', 'created_by'];
public function user() public function user()
{ {

View File

@ -26,6 +26,12 @@ return new class extends Migration
$table->unique(['company_id', 'key', 'deleted_at']); $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']); $table->unique(['company_id', 'key']);
}); });
// User Invitations
Schema::table('user_invitations', function (Blueprint $table) {
$table->dropColumn('created_by');
$table->dropColumn('created_from');
});
} }
}; };