geccomedia/weclapp

Weclapp API通过laravel eloquent实现

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

This package is auto-updated.

Last update: 2024-10-01 00:13:32 UTC


README

Latest Stable Version Total Downloads License

此仓库实现了Weclapp Web API的大多数Laravel Eloquent模型。

安装信息

使用Composer安装此包

composer require geccomedia/weclapp

将变量添加到您的.env文件中

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

使用方法

使用"Geccomedia\Weclapp\Models"命名空间中的现有模型。

大多数Eloquent方法都在Web API的限制内实现。

<?php

use Geccomedia\Weclapp\Models\Customer;

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

自定义模型

示例

<?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';
}

批量赋值

如果您想进行批量赋值,请使用unguardreguard

示例

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

子实体

Weclapp API有一些模型将其视为其他实体的子实体。对于这些情况,我们需要使用whereEntity($name, $id)为查询提供主实体。

示例

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

如果没有调用"whereEntity",API将抱怨我们缺少字段。更多信息请见#22。

日志记录

如果您想查看发出的请求,可以使用Connections日志。

示例

use Geccomedia\Weclapp\Connection;

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

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

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

许可证 & 版权

版权(c)2017 Gecco Media GmbH

许可证