fix(spaces): resolve inviter name without a non-null relation assumption
Larastan treats the invitedBy belongsTo as always present, so the nullsafe access read as unnecessary. Resolve the inviter name via a scalar query keyed on the nullable invited_by_id instead — correct when the inviter's account was deleted (nullOnDelete) and Larastan-clean. Drops the unused invitation view key.
This commit is contained in:
parent
dd43b88fff
commit
ecd1a07a0b
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Mail;
|
namespace App\Mail;
|
||||||
|
|
||||||
use App\Models\SpaceInvitation;
|
use App\Models\SpaceInvitation;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Mail\Mailable;
|
use Illuminate\Mail\Mailable;
|
||||||
|
|
@ -30,7 +31,7 @@ class SpaceInvitationMail extends Mailable implements ShouldQueue
|
||||||
{
|
{
|
||||||
return new Envelope(
|
return new Envelope(
|
||||||
subject: __(':inviter invited you to :space on Whisper Money', [
|
subject: __(':inviter invited you to :space on Whisper Money', [
|
||||||
'inviter' => $this->invitation->invitedBy?->name ?? __('Someone'),
|
'inviter' => User::query()->whereKey($this->invitation->invited_by_id)->value('name') ?? __('Someone'),
|
||||||
'space' => $this->invitation->space->name,
|
'space' => $this->invitation->space->name,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
@ -41,9 +42,8 @@ class SpaceInvitationMail extends Mailable implements ShouldQueue
|
||||||
return new Content(
|
return new Content(
|
||||||
markdown: 'mail.space-invitation',
|
markdown: 'mail.space-invitation',
|
||||||
with: [
|
with: [
|
||||||
'invitation' => $this->invitation,
|
|
||||||
'spaceName' => $this->invitation->space->name,
|
'spaceName' => $this->invitation->space->name,
|
||||||
'inviterName' => $this->invitation->invitedBy?->name ?? __('A Whisper Money user'),
|
'inviterName' => User::query()->whereKey($this->invitation->invited_by_id)->value('name') ?? __('A Whisper Money user'),
|
||||||
'acceptUrl' => route('spaces.invitations.accept', $this->invitation->token),
|
'acceptUrl' => route('spaces.invitations.accept', $this->invitation->token),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
* @property string $token
|
* @property string $token
|
||||||
* @property ?Carbon $expires_at
|
* @property ?Carbon $expires_at
|
||||||
* @property ?Carbon $accepted_at
|
* @property ?Carbon $accepted_at
|
||||||
|
* @property-read Space $space
|
||||||
|
* @property-read ?User $invitedBy
|
||||||
*/
|
*/
|
||||||
class SpaceInvitation extends Model
|
class SpaceInvitation extends Model
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue