M
M
Mokhirjon Naimov2015-03-11 20:47:26
MySQL
Mokhirjon Naimov, 2015-03-11 20:47:26

How to automatically write search query to database (Laravel)?

In Laravel I make the following requests:

Chapter::where('title', 'LIKE', $query)->paginate(10);
Section::where('title', 'LIKE', $query)->paginate(10);
...

That is, different models (and of course different tables). How to make the $query variable automatically written to the database and only when the where() method is used .
Now every time where I make a request Model::where() , then I do:
SearchQuery::create(array(
  'filter_param' => $param,
  'query'        => $query,
  'founds'       => $founds,
));

How to automate this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-03-11
@zvermafia

There really aren't many options:
The relationship between SearchQuery and Chapter/Section is unclear . If there is a separate SearchQuery table , then why search by Chapter/Section ?
It is also not clear when you need to create a new record, under what conditions.
Make a separate service that will manage all search queries, and, accordingly, be responsible for CRUD by $query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question