2017-04-22 58 views
0

FatalThrowableError在myController的 電話未定義的方法stdClass的::通知()電話未定義的方法stdClass的::通知()

laravel通知()未定義的方法。如何解決它....幫助我..

Controller文件:

namespace App\Http\Controllers; 
use Illuminate\Http\Request; 
use DB; 
use Mail; 
use Apps\User; 
use App\Notifications\InvoicePaid; 

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)); 

} 
} 

應用程序/通知/ InvoicePaid.php

namespace App\Notifications; 

use Illuminate\Bus\Queueable; 
use Illuminate\Notifications\Notification; 
use Illuminate\Contracts\Queue\ShouldQueue; 
use Illuminate\Notifications\Messages\MailMessage; 

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!'); 
    } 

} 
+0

爲這是哪種語言添加標籤 – FCin

回答

1

要使用notify方法,你需要添加Notifiable特徵到你的班級。

class User extends Authenticatable { 
    use \Illuminate\Notifications\Notifiable; 

    //... 
} 

如果你不想使用Notifiable特質可以用Notification門面。

Notification::send($users, new InvoicePaid($invoice)); 

更多詳細信息可用here。 Laracasts也有一個視頻。 Watch it here

相關問題