2017-12-08 8 views
0

私はLaravelプロジェクトに取り組んでいます。私はこれらのコマンドを実行し、正常に通知テーブルを作成しました。Laravel Notificationsベーステーブルが見つかりません

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 [ 
       // 
      ]; 
     } 
    } 

誰かがこの上で私を助けることができれば、私は非常にthankfullしなければなりません。

+0

データベース内のテーブル名は何ですか? –

答えて

0

Userオブジェクトのnotificationsの関係は、依然としてNotificationsForAdminと表示されているようです。

モデルにテーブルを指定しないと、テーブルはモデル名のsnake_case文字列として自動的に生成されます。 NotificationsForAdminの場合、これはnotification_for_adminsになります。

パブリックプロパティ$tableを、通知として値が格納されているテーブルの名前でNotificationsForAdminに追加します。これはあなたの問題を解決するはずです。

+0

ありがとうございます。問題は解決される。 –

関連する問題