Hey I want to make a relation between my posts table and my categorie table. But I can't get it working.
Here's my code:
Posts.php (model)
<?php
class Post extends Eloquent
{
protected $table = "posts";
public function categorie()
{
return $this->BelongsTo('Categorie');
}
}
..
Categorie.php (model)
<?php
class Categorie extends Eloquent
{
protected $table = "categories";
public function posts()
{
return $this->hasMany('Post');
}
}
..
PageController.php (controller)
<?php
class PageController extends BaseController
{
public function getIndex()
{
$posts = Post::all();
return View::make('layout.index')->with('posts', $posts);
}
}
How can I show all my posts now with the categories they belong to?
I know if I do $post = Post::find(1)->categorie it returns the categorie that belongs to post id 1 but I want to return all my posts with the categorie