PHPackages                             swisnl/laravel-mautic - 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. swisnl/laravel-mautic

ActiveLibrary[API Development](/categories/api)

swisnl/laravel-mautic
=====================

Laravel wrapper for Mautic API

0.4.1(1y ago)1115.6k↓18.2%1[3 issues](https://github.com/swisnl/laravel-mautic/issues)MITPHPPHP ^8.1CI passing

Since Oct 11Pushed 2mo ago2 watchersCompare

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

READMEChangelog (5)Dependencies (18)Versions (9)Used By (0)

Laravel wrapper for Mautic API
==============================

[](#laravel-wrapper-for-mautic-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e4244309d8d55e7e117c079fb64dca77d3b4c298223ab2ec740c3e5b3574df58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f6c61726176656c2d6d61757469632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/laravel-mautic)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Buy us a tree](https://camo.githubusercontent.com/cec0a9b35a1c3235bdbe0d13ea8fbd866a23e30280ad6ca27078c1fd4ac1b709/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/swisnl/laravel-mautic)[![GitHub Tests Action Status](https://camo.githubusercontent.com/eb39cba6700fa8ebb8c2f865c5411ca4705580c2fece4e1914369bb334f55e27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769736e6c2f6c61726176656c2d6d61757469632f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/swisnl/laravel-mautic/actions/workflows/run-tests.yml?query=branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/df8e1294a62ac1faf2433d9886e3e45c9b961577e92fafe67ca556740be985ef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769736e6c2f6c61726176656c2d6d61757469632f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/swisnl/laravel-mautic/actions/workflows/fix-php-code-style-issues.yml?query=branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/8d7a71825b2e10d882e16b148fc65a287fee358e4cfe54aaa7ebfb919269f256/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737769736e6c2f6c61726176656c2d6d61757469632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/laravel-mautic)[![Made by SWIS](https://camo.githubusercontent.com/ef6bdd6ab8d4f47bceb74dcf558b0915c6b419cbba320096324af0518e43091d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e7376673f7374796c653d666c61742d737175617265)](https://www.swis.nl)

A batteries included Laravel wrapper for Mautic API.

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

[](#installation)

You can install the package via composer:

```
composer require swisnl/laravel-mautic
```

Configuration
-------------

[](#configuration)

Laravel Mautic requires connection configuration.

To get started, you'll need to publish all vendor assets:

```
php artisan vendor:publish --tag="mautic-config"
```

This will create a `config/mautic.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

There are two config options:

##### Default Connection Name

[](#default-connection-name)

This option (`'default'`) is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is `'main'`.

##### Mautic Connections

[](#mautic-connections)

This option (`'connections'`) is where each of the connections are set up for your application. Example configuration has been included, but you may add as many connections as you would like. Note that the 2 supported authentication methods are: `"oauth"` and `"password"`.

Usage
-----

[](#usage)

##### MauticManager

[](#mauticmanager)

This is the class of most interest. It is bound to the ioc container as `'laravel-mautic'` and can be accessed using the `Facades\Mautic` facade. This class implements the `ManagerInterface` by extending `AbstractManager`. The interface and abstract class are both part of my [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at [that repo](https://github.com/GrahamCampbell/Laravel-Manager#usage). Note that the connection class returned will always be an instance of `Swis\Laravel\Mautic\Client`.

##### Facades\\Mautic

[](#facadesmautic)

This facade will dynamically pass static method calls to the `'laravel-mautic'` object in the ioc container which by default is the `MauticManager` class.

##### LaravelMauticServiceProvider

[](#laravelmauticserviceprovider)

This class contains no public methods of interest. This class should be added to the providers array in `config/app.php`. This class will set up ioc bindings.

##### Real Examples

[](#real-examples)

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is `main`. After you enter your authentication details in the config file, it will just work:

```
use Swis\Laravel\Mautic\Facades\Mautic;
// you can alias this in config/app.php if you like

Mautic::contacts()->find(1);
// we're done here - how easy was that, it just works!
```

The mautic manager will behave like it is a `Swis\Laravel\Mautic\Client` class. If you want to call specific connections, you can do with the `connection` method:

```
use Swis\Laravel\Mautic\Facades\Mautic;

// writing this:
Mautic::connection('main')->contacts()->find(1);

// is identical to writing this:
Mautic::contacts()->find(1);

// and is also identical to writing this:
Mautic::connection()->contacts()->find(1);

// this is because the main connection is configured to be the default
Mautic::getDefaultConnection(); // this will return main

// we can change the default connection
Mautic::setDefaultConnection('alternative'); // the default is now alternative

// Get all the contacts
Mautic::contacts()->getList();
```

If you prefer to use dependency injection over facades like me, then you can easily inject the manager like so:

```
use Illuminate\Support\Facades\App; // you probably have this aliased already
use Swis\Laravel\Mautic\MauticManager;

class Foo
{
    protected $mautic;

    public function __construct(MauticManager $mautic)
    {
        $this->mautic = $mautic;
    }

    public function bar()
    {
        $this->mautic->contacts()->find(1);
    }
}

App::make('Foo')->bar();
```

For more information on what features are available on the `Swis\Laravel\Mautic\Client` class, check out the Mautic docs at , and the manager class at .

#### Notifications

[](#notifications)

To use the notification driver built into this package make sure the entity you want to notify has the following traits:

```
class User extends Model
{
    use Notifiable;
    use SynchronizesWithMauticTrait;
    use NotifiableViaMauticTrait;
}
```

Then make sure to add a Notification to your Laravel project. This notification should include the `MauticChannel` from this package in the `via()` method. Make sure your notification includes a `toMautic()` method which returns an instance of `MauticMessage`. For this you can use the `create()` method:

```
