首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用未定义的方法照亮\Notification\Notification::send()

调用未定义的方法照亮\Notification\Notification::send()
EN

Stack Overflow用户
提问于 2017-04-30 12:14:00
回答 3查看 21K关注 0票数 11

我正试图在我的项目中建立一个通知系统。

以下是我所做的工作:

1-php手工通知:表 2-php手工迁移 3-php手工制作:通知AddPost

在我的AddPost.php文件中,我编写了以下代码:

代码语言:javascript
复制
<?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
        ];
    }
}

在我的控制器中,我试图将数据保存在一个表中,而每件事情都是完美的。

这是我控制器中的代码:

代码语言:javascript
复制
<?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');  
    }

}

在我修改这段代码之前,一切都很好:

代码语言:javascript
复制
$post->save();

对此:

代码语言:javascript
复制
if ($post->save())
       {  
        $user=User::all();
        Notification::send($user,new AddPost($post));

       }

它开始显示一个错误,即:

FatalThrowableError在PostNot.php第41行:对未定义方法的调用照亮\通知\通知::PostNot.php()

我要怎么修理这个??

谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-04-30 12:21:32

而不是:

代码语言:javascript
复制
use Illuminate\Notifications\Notification;

你应该使用

代码语言:javascript
复制
use Notification;

现在您使用的是Illuminate\Notifications\Notification,它没有send方法,而Notification facade使用的是有send方法的Illuminate\Notifications\ChannelManager

票数 38
EN

Stack Overflow用户

发布于 2020-08-09 21:18:24

使用此use Illuminate\Support\Facades\Notification;

而不是这个use Illuminate\Notifications\Notification;

帮我解决了这个问题。

希望这能帮上忙。

票数 11
EN

Stack Overflow用户

发布于 2021-07-31 19:29:22

用这个更好

使用通知

而不是

使用照明\支持\正面\通知

这使得send()无法访问#Notification

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43706229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档