Support the ongoing development of Laravel.io →
Database Eloquent

I have a table with a boolean column based on the boolean value.
The boolean value true or false to select the table to relate with:
One table is named zodiac columns('id', 'name') -- for greek zodiac
One table is named zodiacCH columns('id', 'name') --for chinese zodiac
both tables will never get updated they just hold data
Reading table has a column zodiac_id and a boolean column is_chinese

was wondering how to use hasOne based on Reading.is_chinese?
so i can basically do a Reading::find(1)->zodiac
and return the correct table Relationship
Do I need a pivot table?
or should i just create a join and query the db?
currently using
public function zodiac() $bool = $this->query()->first()->is_chinese; if($bool){ return $this->hasOne('App\Models\Horoscope\ZodiacCh', 'id'); }else{ return $this->hasOne('App\Models\Horoscope\Zodiac', 'id'); } } but not working as planned

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

lexonight lexonight Joined 12 Mar 2017

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.