share your models on http://laravel.io/bin...
Probably your reletions definitons can be wrong..
laravel.io/bin/aN1my
used tree/branch/leaf as easiest example to explain
(can't edit)
the place where i'm trying to get post (the leaf) is:
@foreach ($forum->category as $category)
....
{{ count($category->topic->post) }}
....
@endforeach
But like i noted above, it gives the error Undefined property on post. In what way can i access post?
Can you share migration file as you did ?
While searching i came across "hasManyThrough", this sort of skips a part or something? $category->post (instead of $category->topic->post)
Though cant seem to get this to work, you know this?
You can try foreing key to your migration like this http://laravel.io/bin/Yy2qV
In past I don't need "hasManyThrough" relationship our project. I have no experinces..
İf your problem is solved by adding foreing key, You can test relations by unit test..
An Example by using Unit Test from my projects
public function testRelationToProduct() {
$model = new ProCategory;
$this->assertInstanceOf('Product', $model->Products()->getRelated());
}
public function testRelationToProCategory() {
$model = new Product;
$this->assertInstanceOf('ProCategory', $model->ProCategory()->getRelated());
}
I also think that you maybe doesn't know UnitTest.
you can test the relations to models by adding this route to routes.php file
Route::get('test-relations', function () {
$category = new Category();
return var_dump($category->getRelated() instanceof Topic);
});
And than You can check get curl http://localhost/test-relations by via your web browser . Response is true ise reletionships is correct or not..
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community