geccomedia/weclapp

Weclapp api via laravel eloquent

v3.0.0 2023-11-02 00:29 UTC

This package is auto-updated.

Last update: 2024-10-31 00:17:48 UTC


README

Latest Stable Version Total Downloads License

This repo implements most of the Laravel Eloquent Model for the Weclapp web api.

Installation Informations

Require this package with Composer

composer require geccomedia/weclapp

Add the variables to your .env

WECLAPP_BASE_URL=https://#your-sub-domain#.weclapp.com/webapp/api/v1/
WECLAPP_API_KEY=your-key

Usage

Use existing models from "Geccomedia\Weclapp\Models"-Namespace.

Most Eloquent methods are implemented within the limitations of the web api.

<?php

use Geccomedia\Weclapp\Models\Customer;

class YourClass
{
    public function yourFunction()
    {
        $customer = Customer::where('company', 'Your Company Name')
            ->firstOrFail();

Custom models

Example:

<?php namespace Your\Custom\Namespace;

use Geccomedia\Weclapp\Model;

class CustomModel extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'custom-api-route';
}

Mass assignments

If you want to do mass assignment please use unguard and reguard

Example:

$customer = new \Geccomedia\Weclapp\Models\Customer();
\Geccomedia\Weclapp\Models\Customer::unguard();
$customer->fill(['partyType' => 'ORGANIZATION']);
\Geccomedia\Weclapp\Models\Customer::reguard();

Sub Entities

Weclapp api has some models it views as sub entities to other entities. For those cases we need to supply the main entity for the query with whereEntity($name, $id)

Example:

$comments = Comment::whereEntity('customer', 123)->orderByDesc()->get();

Without the call to "whereEntity" the api would complain that we are missing fields. See #22 for more information.

Logging

If you want to see the requests being made, you can use the Connections log

Example:

use Geccomedia\Weclapp\Connection;

app(Connection::class)->enableQueryLog();

\Geccomedia\Weclapp\Models\Customer::create(['name' => 'Test'])

app(Connection::class)->getQueryLog();

License & Copyright

Copyright (c) 2017 Gecco Media GmbH

License