PHP code example of swisnl / laravel-mautic

1. Go to this page and download the library: Download swisnl/laravel-mautic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swisnl / laravel-mautic example snippets


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!

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();

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();

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



namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Swis\Laravel\Mautic\Notifications\MauticChannel;
use Swis\Laravel\Mautic\Notifications\MauticMessage;

class OrderFulfilled extends Notification
{
    use Queueable;

    public function __construct(
        public readonly string $message,
    ) {
    }

    public function via(mixed $notifiable): array
    {
        return [MauticChannel::class];
    }

    public function toMautic(mixed $notifiable): MauticMessage
    {
        return MauticMessage::create(1) // The id of the mail in Mautic
            ->tokens([
                'message' => $message,
            ])
            ->to($mauticUserId); // Optional
    }
}
bash
php artisan vendor:publish --tag="mautic-config"