Added OTS create,store,show
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\OneTimeSecretFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string|null $recipient_type
|
||||
* @property int|null $recipient_id
|
||||
* @property int|null $team_id
|
||||
* @property string $secret
|
||||
* @property string $expires_at
|
||||
* @property CarbonImmutable|null $created_at
|
||||
* @property CarbonImmutable|null $updated_at
|
||||
* @property-read User|Team|null $recipient
|
||||
* @property-read Team|null $team
|
||||
*
|
||||
* @method static \Database\Factories\OneTimeSecretFactory factory($count = null, $state = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereExpiresAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereRecipientId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereRecipientType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereSecret($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereTeamId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|OneTimeSecret whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
#[Fillable(['secret', 'expires_at'])]
|
||||
class OneTimeSecret extends Model
|
||||
{
|
||||
/** @use HasFactory<OneTimeSecretFactory> */
|
||||
use HasFactory, HasUuids;
|
||||
|
||||
public function team(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Team::class);
|
||||
}
|
||||
|
||||
public function recipient(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'secret' => 'encrypted',
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -23,6 +24,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property-read TeamMember|null $pivot
|
||||
* @property-read Collection<int, User> $members
|
||||
* @property-read int|null $members_count
|
||||
* @property-read Collection<int, OneTimeSecret> $receivedOneTimeSecrets
|
||||
* @property-read int|null $received_one_time_secrets_count
|
||||
*
|
||||
* @method static Builder<static>|Team newModelQuery()
|
||||
* @method static Builder<static>|Team newQuery()
|
||||
@@ -53,6 +56,11 @@ class Team extends Model
|
||||
return $this->hasMany(TeamInvite::class);
|
||||
}
|
||||
|
||||
public function receivedOneTimeSecrets(): MorphMany
|
||||
{
|
||||
return $this->morphMany(OneTimeSecret::class, 'recipient');
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
public function scopeVisibleTo(Builder $query, User $user): Builder
|
||||
{
|
||||
|
||||
+16
-8
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Notifications\DatabaseNotificationCollection;
|
||||
@@ -35,6 +36,8 @@ use Laravel\Passkeys\Passkey;
|
||||
* @property-read int|null $notifications_count
|
||||
* @property-read Collection<int, Passkey> $passkeys
|
||||
* @property-read int|null $passkeys_count
|
||||
* @property-read Collection<int, OneTimeSecret> $receivedOneTimeSecrets
|
||||
* @property-read int|null $received_one_time_secrets_count
|
||||
* @property-read TeamMember|null $pivot
|
||||
* @property-read Collection<int, Team> $teams
|
||||
* @property-read int|null $teams_count
|
||||
@@ -64,6 +67,19 @@ class User extends Authenticatable implements MustVerifyEmail, PasskeyUser
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
||||
|
||||
public function teams(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Team::class, 'team_members')
|
||||
->using(TeamMember::class)
|
||||
->withPivot(['role'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function receivedOneTimeSecrets(): MorphMany
|
||||
{
|
||||
return $this->morphMany(OneTimeSecret::class, 'recipient');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
@@ -77,12 +93,4 @@ class User extends Authenticatable implements MustVerifyEmail, PasskeyUser
|
||||
'two_factor_confirmed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function teams(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Team::class, 'team_members')
|
||||
->using(TeamMember::class)
|
||||
->withPivot(['role'])
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user