but I get the error ‘trying to access property of non-object’.
I can print_r the resultant array and all the data is there in a format that should be accessible with the ‘$articles->articles->articleReviews’ syntax.
I tried your way first but it would not work because the ArticleReview table does not share the same FK as the other two (normaiized DB). The only way to get to the data I need is to use ‘with’ in the model which cascades, for lack of a better word, the relations through the the middle table (Article).
The data does in fact get returned; it just doesn’t seem accessible.
I’m sure I need to use multiple foreach statements to break the arrays up but I just can’t seem to get the right depth.
<?php
foreach($articles as $article)
{
echo $article->reviews ;
// you might have to do a foreach within this loop because I think the reviews is an array of review objects
}
<?php
foreach($articles as $article)
{
echo $article->reviews ;
// you might have to do a foreach within this loop because I think the reviews is an array of review objects
}
Thanks guys, that got me on the right track.
With two foreach it works:
foreach($articles as $article)
foreach($article->articles->articleReviews as $review)
I was making it more complex than it needed to be.