我有一个Controller,它监听新的Schedule创建并将其通过ajax发送回 View 。在其中,我想添加一个通知,以便在由于特定日期和时间缺乏资源而无法完成计划时向用户发送电子邮件。
问题是我收到以下错误:
Class 'App\Http\Controllers\Notification' not found in /laravel/app/Http/Controllers/DadosAgendamentoController.php on line 89
文件夹结构是这样的:
-app
-Http
-Controllers
DadosAgendamentoController.php
-Notifications
AgendamentoPendente.php
DadosAgendamentoController.php 头部代码:
namespace App\Http\Controllers;
use Input;
use Request;
use App\Servicos;
use App\Disponibilidades;
use App\Estabelecimentos;
use App\HorariosEstabelecimento;
use App\Agendamento;
use App\User;
use App\Notifications\AgendamentoPendente;
第 88 和 89 行:
$user = User::where('id',1)->get();
Notification::send($user, new AgendamentoPendente(1));
通过我的 Controller ,我可以访问上述所有类,但不能访问 AgendamentoPendente
我的目标是向管理员发送电子邮件,以便他可以在资源在所需日期和时间不可用时向客户建议新的日期和时间。
如何修复?我可以访问这个 Controller 中的类吗?如何?
最佳答案
https://laravel.com/docs/5.3/notifications#sending-notifications
选项 1
您可以使用 notify()
方法:
$user->notify(new AgendamentoPendente(1));
另外,确保
User
类使用 Notifiable
特性:use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
选项 2
使用具有完整命名空间的外观:
\Notification::send($user, new AgendamentoPendente(1));