PHPackages                             cleaniquecoders/global-search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cleaniquecoders/global-search

ActiveLibrary

cleaniquecoders/global-search
=============================

A simplified global search for Laravel Scout

1.5.0(1mo ago)06MITPHPPHP ^8.2 | ^8.3 | ^8.4CI passing

Since Dec 30Pushed 1mo agoCompare

[ Source](https://github.com/cleaniquecoders/global-search)[ Packagist](https://packagist.org/packages/cleaniquecoders/global-search)[ Docs](https://github.com/cleaniquecoders/global-search)[ RSS](/packages/cleaniquecoders-global-search/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (28)Versions (6)Used By (0)

A simplified global search for Laravel Scout
============================================

[](#a-simplified-global-search-for-laravel-scout)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c2c4b4a2c3eaa6eda7b7adf0cdc7a9cad77e4712f07f88ab9acb7aacde79f37b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c65616e69717565636f646572732f676c6f62616c2d7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/global-search)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0235ab5fe013916a19e52ed554b51c38d754896bfeb1b08abe41906b8f0c8d7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f676c6f62616c2d7365617263682f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/cleaniquecoders/global-search/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/4c5b021962b6b71ba64db3051f680e7fdd2cb6d60958f512fae818374381253a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f636c65616e69717565636f646572732f676c6f62616c2d7365617263682f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/cleaniquecoders/global-search/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/ad77a2296f5323bd74551dd375e402a2a516b5eab523622e848d670afbe481d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c65616e69717565636f646572732f676c6f62616c2d7365617263682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/global-search)

A simplified global search URL endpoint for your application.

Installation
------------

[](#installation)

You are required to install [Laravel Scout](https://laravel.com/docs/9.x/scout#installation) first, then choose which driver you preferred to use:

1. [Algolia](https://laravel.com/docs/9.x/scout#algolia)
2. [Meilisearch](https://laravel.com/docs/9.x/scout#meilisearch)
3. [Database](https://laravel.com/docs/9.x/scout#database-and-collection-engines)
4. [Collection](https://laravel.com/docs/9.x/scout#collection-engine)

Then you can install the package via composer:

```
composer require cleaniquecoders/global-search
```

You can publish the config file with:

```
php artisan vendor:publish --tag="global-search-config"
```

Usage
-----

[](#usage)

Configure your model so that it's [searchable](https://laravel.com/docs/9.x/scout#configuring-searchable-data).

Next, add the following in your `routes/api.php`:

```
use CleaniqueCoders\GlobalSearch\GlobalSearch;

GlobalSearch::routes();
```

You may now use the API search route in your front-end:

```
axios.get('search', {
    'type' => 'user',
    'keyword' => 'nasrul'
})
.then(...)
```

If you need to call within your application, from the back-end, you can use the `search()` helper:

```
// get the first result
search(\App\Models\User::class, 'nasrul');

// get all possible result by passing true to the third argument
// this will return a paginated result
search(\App\Models\User::class, 'nasrul', true);
```

To add more search capabilities, you may add more enum values as in `app/Enums/SearchType` class.

```
