Support the ongoing development of Laravel.io →
Database Eloquent

Model Woman extends Homospaien Model Man extends Homosapien

Table "homosapien" contains all fields common to "Woman" and "Man" Tables "woman" and "man", obviously only contain fields unique to each gender.

Anyone got a link to correct docs on how to do this? I want to be able to load $man=Man($id) which would load the row from "man" AND populate the fields from "homosapien"

Last updated 3 years ago.
0
  • Append homosapien's fields to a model that extends eloquent (es. Human) using protected $appends property, take a look at http://laravel.com/docs/eloquent#converting-to-arrays-or-json (last paragraph).
  • Specify custom getter relying on relation between homosapien's and man/woman (hasOne i think).
  • Men and Woman model should extend Human.
  • Using Men::find($id) or Woman::find($id) as usually you can access to the appended fields.

I can't test it at this moment, but should work.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2025 Laravel.io - All rights reserved.