2017-04-22 4 views
0

FatalThrowableError in MyController Call to undefined Methode stdClass :: Notify()Call to undefined Methode stdClass :: Notify()

Laravel notify() nicht definierten Methode. wie man es gelöst .... mir helfen ..

Controller-Datei:

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

} 
} 

app/Benachrichtigungen/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

Fügen Sie Tags hinzu für welche Sprache das ist – FCin

Antwort

1

die notify Methode verwenden müssen Sie die hinzufügen Notifiable Merkmal zu Ihrer Klasse.

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

    //... 
} 

Wenn Sie das Notifiable Merkmal nicht verwenden möchten, können Sie die Notification Fassade verwenden.

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

Weitere Details sind verfügbar here. Laracasts haben auch ein Video darüber. Watch it here.

Verwandte Themen