大佬教程收集整理的这篇文章主要介绍了php-Laravel方法通知不存在,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
BadMethodCallException in Macroable.PHP line 74: Method notify does not exist.
这是通知类
<?PHP
namespace App\Notifications\Admin;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\messages\Mailmessage;
use App\Models\Admin\Forms\Prescriptions;
class PrescriptionNotification extends Notification
{
use Queueable;
public $Prescription;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Prescriptions $Prescription)
{
$this->Prescriptions = $Prescription;
}
/**
* Get the notification's delivery chAnnels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiablE)
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\messages\Mailmessage
*/
public function toMail($notifiablE)
{
$url = url('/admin/prescriptions/edit/'.$this->Prescriptions->id);
return (new MailmessagE)
->line('New form')
->action('View', $url)
->line('');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiablE)
{
return [
'test' => 'test'
];
}
}
在我的控制器中,我正在这样做:
$users = App\User::all()->where('role', 3);
//trigger email notification
$Prescription = Prescriptions::first();
$users->notify(new PrescriptionNotification($Prescription));
正在遵循This教程,但仍然无济于事.我的用户模型中有Notifiable.还有什么可以做的?我不知道是什么导致了此错误.
根据要求,我的User类:
<?PHP
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
//is admin
public function isAdmin()
{
return $this->role; // this looks for an admin column in your users table
}
//relationship with prescription forms
public function confirmations()
{
return $this->hasmany('App\Models\Admin\Forms\Prescription_confirmations', 'physician_id');
}
//relationship with prescriptions forms
public function prescriptions()
{
return $this->hasmany('App\Models\Admin\Forms\Prescriptions', 'physician_id');
}
}
解决方法:
$users是一个集合,因此您在集合上调用notify方法,这将导致错误.并且方法notify仅存在于用户对象实例上.
你可以这样做
<?PHP
foreach ($users as $user) {
$user->notify(new PrescriptionNotification($Prescription));
}
以上是大佬教程为你收集整理的php-Laravel方法通知不存在全部内容,希望文章能够帮你解决php-Laravel方法通知不存在所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。