PHPackages                             loonpwn/laravel-swiftype - 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. [API Development](/categories/api)
4. /
5. loonpwn/laravel-swiftype

ActiveLibrary[API Development](/categories/api)

loonpwn/laravel-swiftype
========================

Swiftype Integration for Laravel

2.0.3(3y ago)72.8k2[1 issues](https://github.com/harlan-zw/laravel-swiftype/issues)[4 PRs](https://github.com/harlan-zw/laravel-swiftype/pulls)MITPHPPHP ^7.3|^8.0|^8.1

Since Nov 1Pushed 1y ago2 watchersCompare

[ Source](https://github.com/harlan-zw/laravel-swiftype)[ Packagist](https://packagist.org/packages/loonpwn/laravel-swiftype)[ Docs](https://github.com/harlan-zw/swiftype)[ RSS](/packages/loonpwn-laravel-swiftype/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (35)Used By (0)

Laravel Swiftype
================

[](#laravel-swiftype)

[![Total Downloads](https://camo.githubusercontent.com/397a7580f407b9ffd83fdf915acf1a63927e236dfaa9517e39211adc09a364e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6c6f6f6e70776e2f6c61726176656c2d73776966747970652e7376673f7374796c653d666c6174)](https://packagist.org/packages/loonpwn/laravel-swiftype)[![Total Downloads](https://camo.githubusercontent.com/e7bff494d4a1c62c9ab2d5dfb5faafe0dce97c2d5f0a2caf5e4e985d90c16970/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6f6e70776e2f6c61726176656c2d73776966747970652e7376673f7374796c653d666c6174)](https://packagist.org/packages/loonpwn/laravel-swiftype)[![StyleCI](https://camo.githubusercontent.com/281f9620b02e70704bb80a877a49caa05750a9b0122e466cc47412e04f5e3355/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3135353633323334372f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/155632347)

Laravel Swiftype is a wrapper for [elastic/app-search](https://www.elastic.co/products/app-search) with some Laravel specific helpers to make integrating your Eloquent Models with Swiftype a breeze.

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

[](#installation)

Via Composer

```
composer require harlan-zw/laravel-swiftype
```

If you do not run Laravel 5.5 (or higher), then add the service provider in `config/app.php`:

```
Loonpwn\Swiftype\SwiftypeServiceProvider::class,

```

Usage
-----

[](#usage)

In your `.env` file, add the following variables.

```
SWIFTYPE_DEFAULT_ENGINE=
SWIFTYPE_API_PRIVATE_KEY=
SWIFTYPE_HOST_IDENTIFIER=

```

Get your keys from the [Swiftype Credentials](https://app.swiftype.com/as#/credentials) page.

When self-hosting an instance of AppSearch, you can use the API Endpoint displayed on the credentials page as `SWIFTYPE_HOST_IDENTIFIER`, e.g.:

```
SWIFTYPE_HOST_IDENTIFIER=http://localhost:3002

```

### API

[](#api)

This packages has two Facades which give you access to the underlying Swiftype client.

#### Swiftype

[](#swiftype)

The `Swiftype` facade is a direct wrapper for the built client from . Any command from the base client can be used on this facade. Example:

- `Swiftype::listEngines($currentPage = null, $pageSize = null)` - Show all engines available
- `Swiftype::createEngine($name, $language = 'en')` - Find an engine based on name

With IDE auto-complete:

```
/** @var \Loonpwn\Swiftype\Clients\Api $api */
$api = app(Swiftype::class);
```

#### SwiftypeEngine

[](#swiftypeengine)

The `SwiftypeEngine` is a wrapper on top of the `Swiftype` facade with direct context of the default engine. Many of the same functions from the core API is available in this facade without the need to specify an engine.

`SwiftypeEngine::search($query, $options)` - Search documents within the engine

`SwiftypeEngine::indexDocument($document)` - Creates a new document, or updates an existing, based on the primary key. This function will use a transformer to make sure the primary key is transformed to just `id`.

`SwiftypeEngine::indesDocuments($document)` - Similar as the above but will take a list of models and chunk them to 100 per request

`SwiftypeEngine::deleteDocument($documentId)` - Removes a document.

`SwiftypeEngine::deleteDocuments($documentIds)` - Takes an array of document ids and removes them.

`SwiftypeEngine::listDocuments($page = 1, $pageSize = 100)` - Lists documents that belong to the engine, with pagination.

`SwiftypeEngine::listAllDocumentsByPages($action, $page = 1, $pageSize = 100)` - Lists documents that belong to the engine, will iterate through all pages and call your custom action.

`SwiftypeEngine::purgeAllDocuments()` - Will remove all documents from Swiftype

### Traits

[](#traits)

`IsSwiftypeDocument` is a trait available which hooks into the models `saved` event hook. The following happens on saved:

- `shouldSyncSwiftypeOnSave` is checked and must pass true to continue
- `getSwiftypeAttributes` is called to get the attributes to send to Swiftype

You should override these functions for business specific logic.

```
/**
 * Should model changes be pushed to Swiftype. Excludes deleting
 * @return bool
 */
public function shouldSyncSwiftypeOnSave()
{
    // by default all model changes are pushed to swiftype
    return true;
}

/**
 * Get the mapped attribute values for Swiftype
 * @return mixed|null
 */
public function getSwiftypeAttributes()
{
    // Document transformer is the default transformer, feel free to implement your own
    return transform($this, new DocumentTransformer());
}
```

### Jobs

[](#jobs)

Currently only jobs directly related to the Eloquent Model events are created. These can be used to queue the data sync.

- `DeleteDocument($documentId)` - Delete a particular document, takes the document id
- `IndexDocument($document)` - Pushes the individual document. Takes the mapped document
- `SyncDocuments` - Iterates through all documents in Swiftype and local DB to find documents out of sync and eithers adds or removes them. This uses the `swiftype.sync_models` configuration

Testing
-------

[](#testing)

```
$ composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 88.9% 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 ~68 days

Recently: every ~202 days

Total

23

Last Release

1256d ago

Major Versions

0.4.0 → 1.0.02019-11-11

1.1.0 → 2.0.02020-09-17

0.2.3 → 2.0.32022-12-04

PHP version history (3 changes)1.1.0PHP ^7.3

2.0.1PHP ^7.3|^8.0

2.0.2PHP ^7.3|^8.0|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c3cc9c67bbfb11d56dbe8aff65500444b1b17cd3f6dcaab17b3235a5691f65a?d=identicon)[harlan-zw](/maintainers/harlan-zw)

---

Top Contributors

[![harlan-zw](https://avatars.githubusercontent.com/u/5326365?v=4)](https://github.com/harlan-zw "harlan-zw (32 commits)")[![matijse](https://avatars.githubusercontent.com/u/5838090?v=4)](https://github.com/matijse "matijse (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

laravelswiftype

### Embed Badge

![Health badge](/badges/loonpwn-laravel-swiftype/health.svg)

```
[![Health](https://phpackages.com/badges/loonpwn-laravel-swiftype/health.svg)](https://phpackages.com/packages/loonpwn-laravel-swiftype)
```

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)[api-ecosystem-for-laravel/dingo-api

A RESTful API package for the Laravel and Lumen frameworks.

3121.5M10](/packages/api-ecosystem-for-laravel-dingo-api)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[kirschbaum-development/laravel-openapi-validator

Automatic OpenAPI validation for Laravel HTTP tests

581.1M5](/packages/kirschbaum-development-laravel-openapi-validator)

PHPackages © 2026

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