Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Having the same issue. Hate to be the bringer of bad news but I have yet to find a solution.

Last updated 1 year ago.
0

Hi guys,

I've had some luck on this front. If you take a look at and follow this guide: http://www.colorfultyping.com/single-table-inheritance-in-lara...

... That'll get you single-table-inheritance... Not what we want, but by adding the following to the BaseModel you can extend it:

private function augmentWithChildData($data, $table) {
	$childData = DB::table($table)->where('id', $data->id)->first();
	return (object) array_merge((array) $data, (array) $childData);
}

Then inside newFromBuilder(), add $attributes = $this->augmentWithChildData($attributes, $instance->mtiChildTable);

You've also need to explicitly set your base table: protected $table = 'user'; and don't override it in the children. Finally, add this variable to each inheriting model: protected $mtiChildTable = 'manufacturer';

It's not the full solution, but hopefully it gets you most of the way there. -Trick

Last updated 1 year 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.

© 2024 Laravel.io - All rights reserved.