rachidlaasri/ycode-php-sdk

PHP and Laravel SDK for working with ycode.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/rachidlaasri/ycode-php-sdk

v0.1.0 2025-12-01 01:06 UTC

This package is auto-updated.

Last update: 2025-12-01 01:16:11 UTC


README

Logo for ycode php sdk

YCODE PHP SDK

Build Status Latest Stable Version License

This package provides better API for working with YCODE API.

Requires PHP 8.3+

Note: Please refer to the official documentation for more details.

Installation

โšก๏ธ Get started by requiring the package using Composer:

composer require rachidlaasri/ycode-php-sdk

Usage

This SDK is framework agnostic, meaning it can be used with any PHP project. But it also provides a fluent API for Laravel integration.

Vanilla PHP

use RashidLaasri\YCODE\Config;
use RashidLaasri\YCODE\YCode;

$configs = new Config(
    baseUrl: 'https://app.ycode.com/api/v1',
    token: '<AUTH-TOKEN>',
);

$project = new YCode($configs);

Laravel

If you are using Laravel, you may publish the configuration file with:

php artisan vendor:publish --tag=ycode-config

Then add these two keys to your .env file:

YCODE_BASE_URL=https://app.ycode.com/api/v1
YCODE_TOKEN=<AUTH-TOKEN>

and then you can resolve it from the IoC.

$project = app(Ycode::class);

Table of Contents

Collections

List all collections

$collections = $project->collections()->list();

Returns an array of RashidLaasri\YCODE\DataObjects\Collection

array:1 [
  0 => RashidLaasri\YCODE\DataObjects\Collection {
    +_ycode_id: "637781341a6f7"
    +name: "Blogposts"
    +singular_name: "Blogpost"
    +created_at: Carbon\Carbon @1668776244
    +fields: []
  }
]

For more details, please check the official documentation.

Get single collection

$collection = $project->collections()->get('637781341a6f7');

Returns an instance of RashidLaasri\YCODE\DataObjects\Collection with fields array

RashidLaasri\YCODE\DataObjects\Collection {
    +_ycode_id: "637781341a6f7"
    +name: "Blogposts"
    +singular_name: "Blogpost"
    +created_at: Carbon\Carbon @1668776244
    +fields: array:1 [
        0 => RashidLaasri\YCODE\DataObjects\Field{
          +id: 1
          +name: "ID"
          +type: "number"
          +default_value: null
        }
    ]
}

For more details, please check the official documentation.

Sites

Publishes site

$sites = $project->sites()->publish();

Returns an array of RashidLaasri\YCODE\DataObjects\Doamin

array:1 [
  0 => RashidLaasri\YCODE\DataObjects\Doamin {
    +name: "example.ycode.site"
  }
]

For more details, please check the official documentation.

Items

List all items

$list = $project->items()->list('16687860798456377a79fce481', [
    'filters' => [
        'Name' => 'Blog',
    ],
]);

Returns a pagination instance

foreach($list->items() as $item)
{
    // $item is an instance of RashidLaasri\YCODE\DataObjects\Item
}

For more details, please check the official documentation.

Get a single item

$item = $project->items()->get('16687860798456377a79fce481', 'abc123');

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  +slug: "blogpost-slug"
  +created_at: Carbon\Carbon @1668786123
  +updated_at: Carbon\Carbon @1668786123
  +created_by: "1669309481596637fa4299184e"
  +updated_by: "1669309527456637fa4576f6dc"
  +summary: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..."
  +main_image: "https://storage.googleapis.com/D46OSM.jpg"
  +thumbnail: "https://storage.googleapis.com/ifJO0DZv.jpg"
  +featured: true
  +author: "16687859744696377a736727d8"
  +categories: array:2 [
    0 => RashidLaasri\YCODE\DataObjects\Category
      +name: "1669309639520637fa4c77eea7"
    }
    1 =>  RashidLaasri\YCODE\DataObjects\Category
      +name: "1669309662211637fa4de338d6"
    }
  ]
  +body: "<p>Lorem ipsum dolor sit ams purus, semper nec tempor et, tincidunt sed justo....</p>"
}

For more details, please check the official documentation.

Create an item

$item = $project->items()->create('16687860798456377a79fce481', [
    // payload
]);

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  ...
}

For more details, please check the official documentation.

Update an item

$item = $project->items()->update('16687868024636377aa7270ea9', 'abc123', [
    // payload
]);

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  ...
}

For more details, please check the official documentation.

Patch an

$item = $project->items()->patch('16687868024636377aa7270ea9', 'abc123', [
    // payload
]);

Returns an instance of RashidLaasri\YCODE\DataObjects\Item

RashidLaasri\YCODE\DataObjects\Item {
  +_ycode_id: "16687860798456377a79fce481"
  +id: 1
  +name: "Blogpost title"
  ...
}

For more details, please check the official documentation.

Delete an item

$item = $project->items()->delete('16687868024636377aa7270ea9', 'abc123', [
    // payload
    '_draft' => true,
]);

Returns JSON response

{
  "deleted": 1
}

For more details, please check the official documentation.

Development

๐Ÿงน Keep a modern codebase with Pint:

composer lint

โœ… Run refactors using Rector

composer refactor

โš—๏ธ Run static analysis using PHPStan:

composer test:types

โœ… Run unit tests using PEST

composer test:unit

๐Ÿš€ Run the entire test suite:

composer test

License

YCODE PHP SDK was created by Rachid Laasri under the MIT license.