我正试图在我的项目中建立一个通知系统。
以下是我所做的工作:
1-php手工通知:表 2-php手工迁移 3-php手工制作:通知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
];
}
}在我的控制器中,我试图将数据保存在一个表中,而每件事情都是完美的。
这是我控制器中的代码:
<?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 extends Controller
{
public function index(){
$posts =DB::table('_notification')->get();
$users =DB::table('users')->get();
return view('pages.chat',compact('posts','users'));
}
public function create(){
return view('pages.chat');
}
public function store(Request $request){
$post=new Post();
//dd($request->all());
$post->title=$request->title;
$post->description=$request->description;
$post->view=0;
if ($post->save())
{
$user=User::all();
Notification::send($user,new AddPost($post));
}
return redirect()->route('chat');
}
}在我修改这段代码之前,一切都很好:
$post->save();对此:
if ($post->save())
{
$user=User::all();
Notification::send($user,new AddPost($post));
}它开始显示一个错误,即:
FatalThrowableError在PostNot.php第41行:对未定义方法的调用照亮\通知\通知::PostNot.php()
我要怎么修理这个??
谢谢。
发布于 2017-04-30 12:21:32
而不是:
use Illuminate\Notifications\Notification;你应该使用
use Notification;现在您使用的是Illuminate\Notifications\Notification,它没有send方法,而Notification facade使用的是有send方法的Illuminate\Notifications\ChannelManager。
发布于 2020-08-09 21:18:24
使用此use Illuminate\Support\Facades\Notification;
而不是这个use Illuminate\Notifications\Notification;
帮我解决了这个问题。
希望这能帮上忙。
发布于 2021-07-31 19:29:22
用这个更好
使用通知
而不是
使用照明\支持\正面\通知
这使得send()无法访问#Notification
https://stackoverflow.com/questions/43706229
复制相似问题