سلام وقت بخیر
در قسمت MagicAuthentication وقتی متد send رو صدا میزنم روی createToken نال برمیگردونه، تلاش کردم متوجهش بشم و موفق نشدم، لطفا راهنمایی بفرمایید .
<?php
namespace App\Services\Auth;
use App\Jobs\SendEmail;
use App\Mail\SendMagicLink;
use App\Models\User;
use App\Models\LoginToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MagicAuthentication
{
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function requestLink()
{
$user = $this->getUser();
$token = $user->createToken()->send([
'remember' => $this->request->has('remember')
]);
dd($token);
}
protected function getUser()
{
return User::where('email', $this->request->email)->firstOrFail();
}
}
<?php
namespace App\Mail;
use App\Models\LoginToken;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class SendMagicLink extends Mailable
{
use Queueable, SerializesModels;
private $token;
private $options;
/**
* Create a new message instance.
*/
public function __construct(LoginToken $token, array $options)
{
$this->token = $token;
$this->options = $options;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Send Magic Link',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
dd($this->buildLink());
return new Content(
markdown: 'email.magic.link',
with: [
'link' => $this->buildLink()
]
);
/*return $this->markdown('email.magic.link')->with([
'link' => $this->buildLink()
]);*/
}
protected function buildLink()
{
return route('auth.magic.login', [
'token' => $this->token
] + $this->options);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
<?php
namespace App\Models;
use App\Jobs\SendEmail;
use App\Mail\SendMagicLink;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Bus;
class LoginToken extends Model
{
/*use HasFactory;*/
protected $fillable = [
'token'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function send(array $options)
{
SendEmail::dispatch($this->user, new SendMagicLink($this, $options));
/*$job = new SendEmail($this->user(), new SendMagicLink($this, $options));
Bus::dispatchNow($job);*/
}
}