W
W
WebDev2016-04-22 15:24:57
Laravel
WebDev, 2016-04-22 15:24:57

Laravel difference where?

What's the difference between

#
->where(function($query) {
                        $query->where('url', 'like', '%facebook.com%');
                        $query->orwhere('url', 'like', '%twitter.com%');
                        $query->orWhere('url', 'like', '%instagram.com%');
                    })

and
->where('url', 'like', '%facebook.com%')
                    ->orwhere('url', 'like', '%twitter.com%')
                    ->orWhere('url', 'like', '%instagram.com%')

The second option takes a very long time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2016-04-22
@kirill-93

The first option creates a subquery, thus grouping the queries.
The second option should not work for a long time. Make sure you put in the correct indexes.
I also advise you to use Debugbar: https://github.com/barryvdh/laravel-debugbar
Monitor slow requests, and then execute the request with the EXPLAIN prefix. Mysql itself will explain why the query is slow (no indexes are used, a temporary table is created, etc.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question