我正在尝试从 ConfirmUserToken 获取令牌并将其附加到通知中的 URL。我正在尝试在 laravel 中创建自定义验证。当我使用 $notifiable->token 时,它没有给我任何结果。如何访问令牌?
注册控制器
foreach ($users as $u) {
$cutoken = ConfirmUserToken::create([
'user_id' => $u->id,
'concerned_user' => $user->id,
'token' => Hash::make(now()),
]);
$cutoken->user()->associate($u);
}
Notification::send($users, new ConfirmUser());
确认用户通知
public function toMail($notifiable)
{
$confirmUrl = url("confirmUser/{$notifiable->id}/{$notifiable->token}");
return (new MailMessage)
->subject('Confirm User')
->greeting("Dear {$notifiable->name},")
->line('Please click the button below to confirm that the concerned user is your staff')
->action('Confirm User', $confirmUrl)
->line('If you did not know the concerend staff, no further action is required.');
}
表/架构
public function up()
{
Schema::create('confirm_user_tokens', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('user_id')->default(0);
$table->unsignedInteger('concerned_user')->default(0);
$table->string('token')->default(0);
$table->string('status')->default('0');
$table->timestamps();
});
}