gentor/mautic-api-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gentor/mautic-api-laravel

Composer 安装命令:

composer require gentor/mautic-api-laravel

包简介

Wrapper on the Mautic API for Laravel 4/5.x

README 文档

README

Wrapper on the Mautic API for Laravel 4/5.x

Installation

Installation using composer:

composer require gentor/mautic-api-laravel

Add the service provider in config/app.php:

Gentor\Mautic\MauticServiceProvider::class,

Add the facade alias in config/app.php:

Gentor\Mautic\Facades\Mautic::class,

Configuration

Change your default settings in app/config/mautic.php:

return [
    'baseUrl' => env('MAUTIC_API_URL'),
    'userName' => env('MAUTIC_API_USERNAME'),
    'password' => env('MAUTIC_API_PASSWORD'),
];

Usage

  • Creating an item
// Create contact
$fields = Mautic::contacts()->getFieldList();

$data = array();

foreach ($fields as $field) {
    $data[$field['alias']] = $_POST[$field['alias']];
}

// Set the IP address the contact originated from if it is different than that of the server making the request
$data['ipAddress'] = $ipAddress;

// Create the contact
$response = Mautic::contacts()->create($data);
$contact = $response[Mautic::contacts()->itemName()];
// Create company
$fields = Mautic::companies()->getFieldList();

$data = array();

foreach ($fields as $field) {
    $data[$field['alias']] = $_POST[$field['alias']];
}

// Create the company
$response = Mautic::companies()->create($data);
$contact = $response[Mautic::companies()->itemName()];
// Create contact with companies
$contact = Mautic::contacts()->createWithCompanies([
    'firstname' => 'Mautic',
    'lasttname' => 'Contact',
    'email' => 'contact@email.com',
    'companies' => [
        [
            'companyname' => 'Company 1',
        ],
        [
            'companyname' => 'Company 2',
        ],
    ],
]);
  • Edit an item
$updatedData = array(
    'firstname' => 'Updated Name'
);

$response = Mautic::contacts()->edit($contactId, $updatedData);
$contact = $response[Mautic::contacts()->itemName()];

// If you want to create a new contact in the case that $contactId no longer exists
// $response will be populated with the new contact item
$response = Mautic::contacts()->edit($contactId, $updatedData, true);
$contact = $response[Mautic::contacts()->itemName()];
  • Delete an item
$response = Mautic::contacts()->delete($contactId);
$contact = $response[Mautic::contacts()->itemName()];
  • Error handling
// $response returned by an API call should be checked for errors
$response = Mautic::contacts()->delete($contactId);

if (isset($response['error'])) {
    echo $response['error']['code'] . ": " . $response['error']['message'];
} else {
    // do whatever with the info
}

Documentation

Mautic API Library

Mautic API Docs

统计信息

  • 总下载量: 10.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-23