I am getting error "No query results for model [App\Posts].", but model returns result corectly. I am trying to use pusher to emit event about new post.
$post = \App\Posts::find(1);
if($post) {
event(new \App\Events\NewPost($post));
}
Event:
class NewPost implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
private $post;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($post)
{
$this->post = $post;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('messages');
}
public function broadcastWith() {
return [
'id' => $this->post->id
];
}
}