我正在尝试在我的项目中制作通知系统这些是我已经完成的步骤:1-php工匠通知:表2-php artisan migrate 3-php artisan make:notification AddPost
在我的AddPost.php文件中我写了这段代码:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class AddPost extends Notification
{
use Queueable;
protected $post;
public function __construct(Post $post)
{
$this->post=$post;
}
public function via($notifiable)
{
return ['database'];
}
public function toArray($notifiable)
{
return [
'data'=>'We have a new notification '.$this->post->title ."Added By" .auth()->user()->name
];
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我试图将数据保存在表中,并且每件事都很完美,这是我的控制器中的代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\User;
//use App\Notifications\Compose;
use Illuminate\Notifications\Notification;
use DB;
use Route;
class PostNot …Run Code Online (Sandbox Code Playgroud)