dimanche 30 avril 2017

Call to undefined method Illuminate\Notifications\Notification::send()

I am trying to make notification system in my project these are the steps i have done: 1-php artisan notifications:table 2-php artisan migrate 3-php artisan make:notification AddPost

in my AddPost.php file i wrote this code:

<?php

namespace App\Notifications;

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

class AddPost extends Notification
{
    use Queueable;


    protected $post;
    public function __construct(Post $post)
    {
        $this->post=$post;
    }


    public function via($notifiable)
    {
        return ['database'];
    }




    public function toArray($notifiable)
    {
        return [
            'data'=>'We have a new notification '.$this->post->title ."Added By" .auth()->user()->name
        ];
    }
}

in my controller i am trying to save the data in a table and every thing was perfect this is my code in my controller:

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\User;
//use App\Notifications\Compose;
use Illuminate\Notifications\Notification;
use DB;
use Route;

class PostNot extends Controller
{
    public function index(){
       $posts =DB::table('_notification')->get();
       $users =DB::table('users')->get();
       return view('pages.chat',compact('posts','users'));


    }
public function create(){

        return view('pages.chat');

    }


public function store(Request $request){
    $post=new Post();
   //dd($request->all());
   $post->title=$request->title;
   $post->description=$request->description;
   $post->view=0;

   if ($post->save())
   {  
    $user=User::all();
    Notification::send($user,new AddPost($post));
   }

   return  redirect()->route('chat');  
    }

}

everything was good until i changed this code:

$post->save();

to this :

if ($post->save())
       {  
        $user=User::all();
        Notification::send($user,new AddPost($post));

       }

it started to show an error which is: FatalThrowableError in PostNot.php line 41: Call to undefined method Illuminate\Notifications\Notification::send()

how to pass this one please?? thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire