Skip to content
Advertisement

Search in the main model relationship in Laravel

I am beginner in Laravel. I have small problem with my code

In my system I have cabinets and boards from which it is made. I’m doing a cupboard builder. Each cabinet has specific plates assigned to it. Each cabinet may have different plates.

In this moment I have:

JavaScript

SelectedPlates – assigned to a product / plate cabinet

Plate – plates

Product – cabinets

I need a searchable display of all boards assigned to a given product / cabinet

I make this function:

JavaScript

this code return me 2 plates:

JavaScript

Now I need search in this plates by:

JavaScript

and filter by

JavaScript

something like this:

JavaScript

The above code doesn’t work. Does not search / filter. how can I make it?

Advertisement

Answer

You need to change few lines of code in order to this work. First add relation for plates and then, for example:

JavaScript

Learn more of whereHas on https://stackoverflow.com/a/30232227/3740460

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement