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

If I understand you correctly, what you are after is a belongsTo - hasMany relationship or one to many. It's not polymorphic.

If you read it out: a BOOK belongs to a CATEGORY

A CATEGORY has many BOOKS

So in your book table, you'd have a category_id field.

http://laravel.com/docs/5.1/eloquent-relationships#one-to-many

Just make sure this is definately the right approach and you won't want a book to have more than one category. It would be a pain down the line if you had to change it.

Hope it helps.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

fzhan fzhan Joined 4 Apr 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.