Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ganskoff's avatar

Universal Search within Website

Is it possible to pass a model type into a function to, in essence, create a dynamic universal search?

ie. Zones, Equipment, People

Then do something like

public function search (Model $m)
{
    $query = (new $m)->newQuery();
    dd($query->get());
}

So if I have a People page, I can pass over the People model to get all results for the People page, and vice versa with other sections.

I started working on a Laravel project and I've just moved onto the 'search' functionality. Instead of making a search section for each model, can I make a search framework and just pass in which model I want using filters outlined in the search framework?

0 likes
2 replies
lostdreamer_nl's avatar

Sure you can (your example already works)..... But I wouldn't.

Now the search class would need to know all fields to search for any model, usually this is knowledge of the Model itself. (Does Model Zone have a name or a title, should we search through people.name or also through people.skills etc.)

Ganskoff's avatar

@lostdreamer_nl

Each section (People, Zones, Equipment) would have different columns. There are common columns (Name, etc.) but Zones wouldnt have a Cost column where Equipment would.

I dont know where to start but the basic idea is to have a text field search for name and then allow dropdowns, textboxes, etc. as filters.

In theory I'd like to have the results of 'All' list on the landing section so, All People and then filter accordingly if they were applied. Does that mean I have to make a search feature for each section?

Please or to participate in this conversation.