PHPackages                             algolia/laravel-scout-algolia-macros - 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. [Search &amp; Filtering](/categories/search)
4. /
5. algolia/laravel-scout-algolia-macros

ActiveLibrary[Search &amp; Filtering](/categories/search)

algolia/laravel-scout-algolia-macros
====================================

A collection macros to extend Laravel Scout with more Algolia capabilities

0.6.0(7y ago)3633.7k↓66.7%8MITPHP

Since Jun 12Pushed 7y ago68 watchersCompare

[ Source](https://github.com/algolia/laravel-scout-algolia-macros)[ Packagist](https://packagist.org/packages/algolia/laravel-scout-algolia-macros)[ Docs](https://github.com/algolia/laravel-scout-algolia-macros)[ RSS](/packages/algolia-laravel-scout-algolia-macros/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (1)Versions (8)Used By (0)

**DEPRECATED: Use of this repository is deprecated. Please use Scout Extended -  instead.**

Laravel Scout Algolia Macros
============================

[](#laravel-scout-algolia-macros)

A collection of useful macros to extend Laravel Scout capabilities when using the [Algolia engine](https://laravel.com/docs/5.4/scout#driver-prerequisites).

This package aims to provide a set of macros to take advantage of the Algolia-specific feature.

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

[](#installation)

Pull the package using composer

```
composer require algolia/laravel-scout-algolia-macros

```

Next, you should add the `Algolia\ScoutMacros\ServiceProvider` to the `providers`array of your `config/app.php` configuration file:

```
Algolia\ScoutMacros\ServiceProvider::class
```

Usage
-----

[](#usage)

### `count`

[](#count)

The count method will return the number of results after the request to Algolia.

The point is to avoid pull data from the database and building the collection.

```
$nbHits = Model::search('query')->count();
```

### `hydrate`

[](#hydrate)

The `hydrate` method is similar to the standard get() method, except it hydrates the models from your Algolia index.

By default, Scout will use the IDs of the results from Algolia and pull the data from the local database to create the collection.

Hence, `hydrate` will be much faster than `get`.

**Note**: By using this method you must be sure that you are correctly keeping your algolia index in sync with your database to avoid populating stale data.

#### Restrict attributes

[](#restrict-attributes)

By default, this method will add all attributes from Algolia's record to your model. If you want to remove sensitive or irrelevant data from your model, you have two options.

You can set a list of retrievable attributes in your Algolia dashboard. In this case, Algolia will only return these attributes while still searching every `searchableAttributes`.

You may as well use the laravel `$guarded` attributes of your model class. For instance, if you don't want to see the `_h` attribute in your collection, you will have the following.

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class People extends Model
{
    use Searchable;

    protected $guarded = ['_highlightResult'];
}
```

### `with`

[](#with)

The `with` method gives you complete access to the Algolia options parameter. This allows you to customise the search parameters exactly the same as you would using the algolia php library directly.

#### Simple example

[](#simple-example)

```
$result = Model::search('')
					->with(['hitsPerPage' => 30])
					->get();
```

#### Advanced example

[](#advanced-example)

```
$filters = [
    'averge_ratings >= 3',
    'total_reviews >= 1'
];

$filterString = implode(' AND ', $filters);

$params = [
            'aroundLatLng' => $lat.','.$lon,
            'hitsPerPage' => 30,
            'page' => 0,
            'aroundRadius' => 30000, //30km
            'aroundPrecision' => 200, //200 Meters
            'getRankingInfo' => true, //return ranking information in results
            'filters' => $filterString // add filters
        ];

$result = Model::search('')->with($params)->get();
```

### `aroundLatLng`

[](#aroundlatlng)

The`aroundLatLng` method will add [geolocation parameter](1) to the search request. You can define a point with its coordinate.

Note that this method is pure syntactic sugar, you can use `with` to specify more location details (like radius for instance)

```
// Models around Paris latitude and longitude
Model::search('query')->aroundLatLng(48.8588536, 2.3125377)->get();
```

Where clauses can also be added

```
Model::search('query')
    ->aroundLatLng(48.8588536, 2.3125377)
    ->where('something_id', 1)
    ->get();
```

Contributing
------------

[](#contributing)

Feel free to open an issue to request a macro.

Open any pull request you want, so we can talk about it and improve the package. 🎉

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~89 days

Recently: every ~104 days

Total

6

Last Release

2807d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd7b3a0ca4d58fca8b57cfd28ac17cb1e37b5fc6f92376b725a9d22f3d94379e?d=identicon)[julienbourdeau](/maintainers/julienbourdeau)

![](https://www.gravatar.com/avatar/41b2c9ca6c01f18e470d2b1978227f8538e7af7031b8b05235aed5f6e186c2f1?d=identicon)[RayRutjes](/maintainers/RayRutjes)

---

Top Contributors

[![julienbourdeau](https://avatars.githubusercontent.com/u/1525636?v=4)](https://github.com/julienbourdeau "julienbourdeau (29 commits)")[![rayrutjes](https://avatars.githubusercontent.com/u/5570853?v=4)](https://github.com/rayrutjes "rayrutjes (11 commits)")[![robbydooo](https://avatars.githubusercontent.com/u/3592735?v=4)](https://github.com/robbydooo "robbydooo (6 commits)")[![gerciljunio](https://avatars.githubusercontent.com/u/4561073?v=4)](https://github.com/gerciljunio "gerciljunio (3 commits)")[![bastien-phi](https://avatars.githubusercontent.com/u/10199039?v=4)](https://github.com/bastien-phi "bastien-phi (1 commits)")[![AshPowell](https://avatars.githubusercontent.com/u/7704739?v=4)](https://github.com/AshPowell "AshPowell (1 commits)")[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (1 commits)")

---

Tags

algoliaalgolia-searchlaravel-packagelaravel-scoutsearchsearchalgoliasearch enginelaravel scoutlaravel macros

### Embed Badge

![Health badge](/badges/algolia-laravel-scout-algolia-macros/health.svg)

```
[![Health](https://phpackages.com/badges/algolia-laravel-scout-algolia-macros/health.svg)](https://phpackages.com/packages/algolia-laravel-scout-algolia-macros)
```

###  Alternatives

[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

4186.3M6](/packages/algolia-scout-extended)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[devnoiseconsulting/laravel-scout-postgres-tsvector

PostgreSQL Full Text Search Driver for Laravel Scout

58110.1k](/packages/devnoiseconsulting-laravel-scout-postgres-tsvector)[algolia/laravel-scout-settings

Import/Export Algolia settings into your Laravel Scout project

23396.9k](/packages/algolia-laravel-scout-settings)[zing/laravel-scout-opensearch

Laravel Scout custom engine for OpenSearch

33340.2k](/packages/zing-laravel-scout-opensearch)[cmsig/seal

Search Engine Abstraction Layer

32207.9k53](/packages/cmsig-seal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
