Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Hey,

first: that's a One-to-Many relationship. ONE Category can have MANY questions.

You confused the methods. You need a hasMany relationship in the categories (since every category has multiple questions) and a belongsTo relationship in the questions (since every question belongs to one category).

After that you can say

$question->category->cat_name
0

Thank you.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

wjohnw wjohnw Joined 14 Oct 2015

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.