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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community