This package provides better API for working with YCODE API.
Requires PHP 8.3+
Note: Please refer to the official documentation for more details.
⚡️ Get started by requiring the package using Composer:
composer require rachidlaasri/ycode-php-sdkThis SDK is framework agnostic, meaning it can be used with any PHP project. But it also provides a fluent API for Laravel integration.
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);If you are using Laravel, you may publish the configuration file with:
php artisan vendor:publish --tag=ycode-configThen 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);$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.
$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 = $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.
$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.
$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.
$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.
$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.
$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.
$item = $project->items()->delete('16687868024636377aa7270ea9', 'abc123', [
// payload
'_draft' => true,
]);Returns JSON response
{
"deleted": 1
}For more details, please check the official documentation.
🧹 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 testYCODE PHP SDK was created by Rachid Laasri under the MIT license.