matchish / laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout
MIT License
702 stars 113 forks source link

[Feature] Change app namespace call in commands #243

Open danielcarney96 opened 1 year ago

danielcarney96 commented 1 year ago

Is your feature request related to a problem? Please describe. We are using a non-standard folder structure for our app in which the searchable models live in a different namespace to the namespace defined in laravel's Application.php.

Because of this the flush and import commands do not pickup our models since they use the method app()->getNamespace().

Describe the solution you'd like Either a different method for finding the models or a way to configure the namespace to look in.

algolia/scout-extended uses an approach which looks at the root composer.json file and collects the autoload mappings. Perhaps with some changes to ignore the common database namespaces this would be a good approach. See: https://github.com/algolia/scout-extended/blob/bf3d7876fadaaa1cdbce3a09cfd256227406a3fc/src/Helpers/SearchableFinder.php#L116

Alternatively this could be managed via config. Perhaps with a default value of App\\ or app()->getNamespace().

Describe alternatives you've considered We can't extend the existing commands so as a workaround we have just copied them as a way of overwriting, then have changed the namespace function call. But this is not ideal as we will need to keep it up to date.

matchish commented 1 year ago

Yeah following algolia-extended approach is good idea. Feel free to open PR

danielcarney96 commented 1 year ago

Sure, will get around to it when I can