I am having problem accessing eloquent's association from within VueJS component via props.
So am passing a model object to vue component, like this:
Comment model
public function post()
{
return belongsTo('App\Post');
}
Comment controller
$comments = Comment::all()
return view('comments', ['comments' => $comments);
comment blade
<comment-index :comments="{{ $comments }}"></comment-index>
comment vue component
<template>
<div>
<table>
<tr v-for="comment in comments">
<td>{{ comment.message }}
<td>{{ comment.post.title }} // post is undefined
</tr>
</table>
</div>
</template>
<script>
export default {
props: ['comments']
}
</script>
But if if I loop and dump the post in the controller, the post shows in the vue template:
$comments = Comment::all()
foreach($comments as $comment) {
dump($comment->post->title);
}
return view('comments', ['comments' => $comments);