Laravel 9: Scout with NEW Database Driver

preview_player
Показать описание
In Laravel 9, they introduced a new driver to Laravel Scout, that would search in your local database, instead of an external engine like Algolia, Elasticsearch, or Meilisearch.

Related links:

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

Managed to load relationship on my previous project using Scout with Meilisearch driver. You have to load relations inside query builder closure. Btw, Meilisearch is great if you don't want to setup the massive Elasticsearch or pay for cloud solutions (Algolia/ElasticCloud).

$locations = (Builder $builder) use $uniqueValue {
$builder->where('field',
})->paginate(15);

the $uniqueValue is an outside variable to 'fixed' filter the search throughout the same search session. (e.g: userId). No need to use it if you don't have to.

muhaimintaib
Автор

At least with Algolia you can define relationships in your model

Here's an example implementation where you're searching all of one model and then a relationship (categories)

public function toSearchableArray()
{
$array = $this->toArray();

$array = $this->transform($array);

$array['categories'] = ($data) {
return $data['name'];
})->toArray();

return $array;
}

ChrisWinfieldBlum
Автор

A search that doesn’t work with eloquent relationships? Complete dealbreaker for me. It’s easy enough to just write a custom search yourself. This video saved me some time, as I was about to use Scout. Now I know not to waste my time on it. Seems like others in the comments have workarounds, but it’s easier to just code the search myself.

phoenixedge
Автор

I guess Algolia or Elasticsearch (or whatever fulltext search engine) would do the trick with relations. The only downside is that you will have to perform indexing of the DB to that search engine. Also, the performance - not all servers are capable of running Docker container with Elasticsearch in it, since it's quite heavy (not sure about Algolia though). But yeah - I am considering to introduce ES to my project, since customer wants to search users by partially name and surname (like "Jo Sm" if it is John Smith) and building mega-queries in the controller (or in repository in my case) is not the best idea ever.

cardboarddignity
Автор

Haven't tried it yet but skimming through the docs, it seems you could use 'makeAllSearchableUsing()' to do your eager loading on the models, and then adding them to search in 'toSearchableArray()' but I could be wrong, see 'Modifying The Import Query' in the docs, anyways thanks for the video

nabil_eisa
Автор

{
$query->with('relation');
})->paginate(10);

sarkhanrasimoghlu
Автор

I have been wondering the overall purpose of Scout. I have been using local scopes for "searchable" database queries. I find that I have total control over how the query is behaves. Also works well with relationships. The controller stays the same but only one more function in the model.

MonethiTebohoArthurnacious
Автор

Bro, you can just do pluck IDs on search and where in in the model alongside with eager loading

prozacsf
Автор

Can you make a video about scout and elasticsearch? With relations search. On Algolia its easy but i want to see how you doing it in elasticsearch

sarkhanrasimoghlu
Автор

rarely see Povilas using Larastater instead of QuickAdminPanel xD

chengkangzai
Автор

Hi, Thanks for this video, I know search is very useful I always use Algolia. I just want to know one thing, is it possible if user spell wrong but need to show correct result? EG: If user search 'Calofornua' can we show results to actual word 'California' ?

akashsharma
Автор

I have a question, is it possible to add LOWER() function to index in sql query when we use scout?

firdavs.ibodullayev
Автор

Hello, sir. For the index.blade, no need to add anything?

ayuma
Автор

Sorry I'm a little bit late, but a possible solution for searching in relations, could it be to add on the searcheable array and index called 'country' => this->country->name or wouldn't work? maybe it will generate a N + 1 issue there right?

DarthVinsus
Автор

I think that Laravel Scout is like spatie/laravel-searchable

elmarzougui
Автор

Please make a video on integrating google shopping feed api on Laravel. Really Needed that

MrThito
Автор

Can't you add relationship values in the searchable array definition in the model. This is kind of how algolia does it. If that works, ot sure however this would impact the performance, e.g. n±1 issues.Just thinking out loud here, didn't test anything

ndeblauw
Автор

Seems like a PR to search on eager loaded relationships should have no problems in getting approved?

aoporanu
Автор

Thanks. It looks easy but what do You think the performance?

GergelyCsermely
Автор

Firstly I'm sorry for my irrelevant question. Could you please explain what is the difference between make:channel and make:event? Are those the same things with just different directories and namespaces? Or their usages and functionality are different? Thenk you.

rezamortezaie