my problem is that i can't seem to return a newly created record with it's relationships to a event.
i have this store method.
public function store(Request $request){
$post = new Post($request->all());
$post->user_id = Auth::user()->id;
$post->save();
$createdPost = Post::with('owner')->findOrFail($post->id);
event(new PostCreatedEvent($createdPost));
return $createdTicket;
}
now i expect this to return data like
{
"post": {
"id": 10,
"title": '"hello",
"body": "world",
"user_id": 1,
"created_at": date,
"updated_at": date,
"owner": {
"id": 1,
"name": "name",
"email": "[email protected]"
}
}
}
And i do get this from the return in the store method. But in the event that gets sent to pusher i get this
{
"post": {
"id": 10,
"title": '"hello",
"body": "world",
"user_id": 1,
"created_at": date,
"updated_at": date,
}
}
My question is why does the event strip out the owner data from before sending it to pusher and how can i fix it.
It seems like there is something happening with the data when it gets to the event class. After not being able to fix it i tried some random solutions.
$createdPost = Post::with('owner')->findOrFail($post->id)->toJson();
This did the trick. I now need to json parse it on the frontend but all the data is coming through.