Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 1 year ago.
0

Define category relation for Post models (supposing you have 'Category' model)

public function category(){
    return $this->belongsTo('Category');
}

Now from a post you can access to category:

$post = Post::find(1);
echo $post->category->type;

Take a look at this link: http://laravel.com/docs/eloquent#relationships

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jbradley22 jbradley22 Joined 23 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.