mardi 1 mai 2018

Type error php laravel broadcasting

When I set up broad casting I get this error r: Argument 1 passed to App\Events\MessagePosted::__construct() must be an instance of App\Events\Message, instance of App\Message given, called in /var/www/epg/app/Http/Controllers/MessageController.php on line 25 /var/www/epg/app/Events/MessagePosted.php#37

This is what I have in my controller broadcast(new MessagePosted($message, $user))->toOthers();

It should broad cast the message and the user to that event

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Message;
use App\Events\MessagePosted;


class MessageController extends Controller
{
//

public function store(Request $request) {
    // Store the new message
    $user = Auth::user();

    $message = $user->messages()->create([
        'message' => $request->get('message')
    ]);


    // Announce that a new message has been posted
    broadcast(new MessagePosted($message, $user))->toOthers();

    return ['status' => 'OK'];
}
public function index(){
    return Message::with('user')->get();
}

}

I do not understand what is going on since what I have seen people say check you imports but I imported the right classes in the controller.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2rcC14h
via IFTTT

Aucun commentaire:

Enregistrer un commentaire