gpt4 book ai didi

mysql - Laravel 通知基表未找到

转载 作者:行者123 更新时间:2023-11-29 18:07:22 25 4
gpt4 key购买 nike

我正在开发一个 Laravel 项目。我运行了这些命令并成功创建了通知表。

php artisan notifications:table
php artisan migrate

一切都很顺利。后来我创建了一个模型名称“NotificationsForAdmin”,迁移名为“notifications_for_admin”,然后我放弃了这个表。现在,当我尝试生成一些通知时,它向我显示此错误,我不知道发生了什么,我在数据库中有通知表,这是具有完美架构的 laravel 通知所需的。错误是:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'followup.notification_for_admins' doesn't exist (SQL: select * from `notification_for_admins` where `notification_for_admins`.`user_id` = 2 and `notification_for_admins`.`user_id` is not null)

我的通知是:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use App\User;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage;
use App\Events\NewEmailReceivedEvent;
use Auth;

class NewEmailReceived extends Notification
{
use Queueable;

public $sender_id, $receiver_id, $sender_name, $receiver_name, $sender_type, $receiver_type, $type, $recipient, $from_email, $subject, $message, $image, $receiver_image, $attachments, $sizesOfAttachments, $originalFileNames, $thread_id, $id_of_email;

/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($sender_id, $receiver_id, $sender_name, $receiver_name, $sender_type, $receiver_type, $type, $recipient, $from_email, $subject, $message, $image, $receiver_image, $attachments, $sizesOfAttachments, $originalFileNames, $thread_id, $id_of_email)
{
$this->sender_id = $sender_id;
$this->receiver_id = $receiver_id;
$this->sender_name = $sender_name;
$this->receiver_name = $receiver_name;
$this->sender_type = $sender_type;
$this->receiver_type = $receiver_type;
$this->type = $type;
$this->recipient = $recipient;
$this->from_email = $from_email;
$this->subject = $subject;
$this->message = $message;
$this->image = $image;
$this->receiver_image = $receiver_image;
$this->attachments = $attachments;
$this->sizesOfAttachments = $sizesOfAttachments;
$this->originalFileNames = $originalFileNames;
$this->thread_id = $thread_id;
$this->id_of_email = $id_of_email;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
$notifications = Auth::user()->notifications;
if ($notifications[7]->shown == 1) {
return ['mail', 'database'];
}
else{
return ['database'];
}
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'sender_id' => $this->sender_id,
'receiver_id' => $this->receiver_id,
'sender_name' => $this->sender_name,
'receiver_name' => $this->receiver_name,
'sender_type' => $this->sender_type,
'receiver_type' => $this->receiver_type,
'type' => $this->type,
'recipient' => $this->recipient,
'from_email' => $this->from_email,
'subject' => $this->subject,
'message' => $this->message,
'image' => $this->image,
'receiver_image' => $this->receiver_image,
'attachments' => $this->attachments,
'sizesOfAttachments' => $this->sizesOfAttachments,
'originalFileNames' => $this->originalFileNames,
'thread_id' => $this->thread_id,
'id_of_email' => $this->id_of_email,
];
event(new NewEmailReceivedEvent($NewEmailReceivedRequest));
return $NewEmailReceivedRequest;
}

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject("New email from ".$this->sender_type)
->greeting('Hello!')
->markdown('mails.NewEmailReceived' , ['recipient_name' => $this->receiver_name , 'subject' => $this->subject , 'mailMessage' => str_limit($this->message, 50) , 'avatar' => $this->image]);
}


/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}

如果有人能在这方面帮助我,我将非常感激。

最佳答案

看来您的 User 对象上的 notifications 关系仍然引用 NotificationsForAdmin

如果您没有为模型指定表,则该表将自动生成为模型名称的 Snake_case 字符串。对于NotificationsForAdmin,这将变为notification_for_admins

将公共(public)属性 $table 添加到您的 NotificationsForAdmin 中,并将存储通知的表的名称作为值。这应该可以解决您的问题。

关于mysql - Laravel 通知基表未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47717511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com