Laravel 通知通道

发布于 2025-01-20 04:15:33 字数 630 浏览 1 评论 0原文

我收到此错误,我该怎么办? 实在找不到我想念的东西。

未定义函数 App\Console\Commands\Notify

这是命令:

    public function handle()
    {
        $user = DB::table('users')
        ->whereIn('role',['athlete'])
        ->andWhere('contact_number');
        $user = notify(new SendSMS);
    }
}

通知:

    public function via($notifiable)
    {
        return [TwilioChannel::class];
    }

    public function toTwilio($notifiable)
    {
        return (new TwilioSmsMessage())
            ->content("Hi {$notifiable->first_name}. Your account was approved!");
    }
}

谢谢!

I am getting this error, what should i do?
Can't really find what I miss.

Undefined function App\Console\Commands\Notify

Here is the command:

    public function handle()
    {
        $user = DB::table('users')
        ->whereIn('role',['athlete'])
        ->andWhere('contact_number');
        $user = notify(new SendSMS);
    }
}

The notification:

    public function via($notifiable)
    {
        return [TwilioChannel::class];
    }

    public function toTwilio($notifiable)
    {
        return (new TwilioSmsMessage())
            ->content("Hi {$notifiable->first_name}. Your account was approved!");
    }
}

Thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画中仙 2025-01-27 04:15:33

notifyNotifying 特征的一种方法,你也不能从数据库查询中调用通知,你应该使用你的 Eloquent 模型,也
您需要将 Notifying 添加到您的 User 模型

示例:

$user = User::whereIn('role',['athlete'])
    ->where('contact_number', 'some value')
    ->get();
$user->each->notify(new SendSMS());

我希望它有帮助

notify is a method of the Notifiable trait, also you cant call notify from the DB query you should use your Eloquent Model, also
you need to add Notifiable to your User model

Example :

$user = User::whereIn('role',['athlete'])
    ->where('contact_number', 'some value')
    ->get();
$user->each->notify(new SendSMS());

I hope it's helpful

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文