代码之家  ›  专栏  ›  技术社区  ›  Ameer Hamza

未找到Laravel通知基表

  •  1
  • Ameer Hamza  · 技术社区  · 6 年前

    我正在做一个拉雷维尔项目。我运行了这些命令并成功创建了通知表。

    php artisan notifications:table
    php artisan migrate
    

    一切都进行得很顺利。后来,我创建了一个名为“NotificationsForAdmin”的模型,迁移名为“notifications\u for\u 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 [
                    //
                ];
            }
        }
    

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   Jerodev    6 年前

    看起来你的 notifications 您的关系 User 对象静止引用 NotificationsForAdmin .

    如果未指定模型的表,则该表将自动生成为模型名称的snake\u大小写字符串。假使 Radmin通知 这变成了 notification_for_admins .

    添加公共属性 $table 到您的 Radmin通知 以存储通知的表的名称作为值。这应该可以解决你的问题。