Answer the question
In order to leave comments, you need to log in
Why do related Eloquent model properties disappear when passed via ajax?
The Chat model has an associated Message model via an associated messages property:
public function messages(){
return $this->hasMany(Message::class);
}
return $chat->firstOrCreate([
'product_id' => $data['product_id'],
'user_id' => $data['user_id']
]);
$.get(
"/chat/get_messages",
{data:data},
function (result)
{
console.log(result.messages);
}
);
$result= $chat->firstOrCreate([
'product_id' => $data['product_id'],
'user_id' => $data['user_id']
]);
$result->messages=$result->messages??null;
return $result;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question