MyController中的致命性致电未定义的方法stdclass :: notify((
laravel notify((未定义的方法。如何解决它....帮助我..
控制器文件:
namespace AppHttpControllers;
use IlluminateHttpRequest;
use DB;
use Mail;
use AppsUser;
use AppNotificationsInvoicePaid;
class BlogController extends Controller
{
public function EmailNotify(){
$user = DB::table('users')->where('id',2)->first();
$urlData = DB::table('url')->where('id',2)->first();
$user->notify(new InvoicePaid($urlData));
}
}
app/notifications/invoicePaid.php
namespace AppNotifications;
use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;
class InvoicePaid extends Notification
{
use Queueable;
protected $toto;
public function __construct($toturial)
{
$this->toto=$toturial;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
}
要使用notify
方法,您需要将Notifiable
特征添加到您的类中。
class User extends Authenticatable {
use IlluminateNotificationsNotifiable;
//...
}
如果您不想使用Notifiable
特质,则可以使用Notification
立面。
Notification::send($users, new InvoicePaid($invoice));
更多详细信息可在此处找到。Laracasts也有一个视频。在这里观看。