KimG left a reply on Parent And Grandchildren Classes In Laravel, Using Same Table?
It's not clear to me how your link is relevant. It looks like it's about doing joins on database tables to find grandchildren objects; this problem has only one database table, and is not a question about joins.
Also remember to escape special characters for a like query...
I'm not sure if this is the culprit, but I think you have an unnecessary space in your query -
->orWhere('infos.name', 'like', '% '.$name.'%');
->orWhere('infos.name', 'like', '%'.$name.'%');
KimG started a new conversation Parent And Grandchildren Classes In Laravel, Using Same Table?
I am rewriting an old program into Laravel at the moment.
The old program had items in it. There was a parent class, Items, and then a number of child classes such as: Weapon, HealingItem, etc, that added additional capabilities. Then there were "grandchildren" classes such as Battle Axe and Whip, which sometimes added additional capabilities but most of the time added flavor text to the existing capabilities of their parent classes.
There was a single database table for all of the items. This table had one column, type, which would determine which of the many grandchildren were instantiated when an item was looked up by ID (or by who owned it in the case of getting a collection of items)
What would be the cleanest way to rewrite this into Laravel? I can make an Item model, but it's not clear to me how I ought to go about "morphing" that item's behaviors based on a "type" column. All of the methods I've considered feel... kinda hackey and hard to maintain.