dev-master
9999999-dev
MIT
The Requires
- laravel/framework ^5.6
- kalnoy/nestedset ^4.3
- optix/draftable dev-master
- optimuscms/media dev-master
- plank/laravel-metable ^1.1
by Jack Robertson
v0.1-alpha
0.1.0.0-alpha
MIT
The Requires
by Jack Robertson
Wallogit.com
2017 © Pedro Peláez
This package provides the core backend functionality for creating pages and page templates within the CMS., (*1)
This package can be installed through Composer., (*2)
composer require optimuscms/pages
In Laravel 5.5 and above the package will autoregister the service provider., (*3)
In Laravel 5.4 you must install this service provider:, (*4)
// config/app.php
'providers' => [
...
Optimus\Pages\PageServiceProvider::class,
...
];
The API follows standard RESTful conventions, with responses being returned in JSON. Appropriate HTTP status codes are provided, and these should be used to check the outcome of an operation., (*5)
Pages, (*6)
Templates, (*7)
List all pages., (*8)
GET /admin/api/pages
Request Body, (*9)
| Parameter | Required | Type | Description |
|---|---|---|---|
parent |
No | int |
A page ID. When provided will only show pages that have this page as their parent. |
Example Response, (*10)
{
"data": [
{
"id": 1,
"title": "A root page",
"slug": "a-root-page",
"uri": "a-root-page",
"has_fixed_uri": true,
"parent_id": null,
"template": "default",
"has_fixed_template": true,
"contents": [
{
"id": 1,
"key": "content",
"value": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium."
}
],
"media": [
{
"id": 1,
"folder_id": null,
"name": "Image",
"file_name": "image.jpg",
"disk": "public",
"mime_type": "image/jpeg",
"size": 102400,
"group": "image",
"created_at": "2018-12-25 10:15:12",
"updated_at": "2018-12-25 10:15:12"
}
],
"children_count": 1,
"is_stand_alone": false,
"is_published": true,
"is_deletable": true,
"created_at": "2019-02-19 09:36:23",
"updated_at": "2019-02-19 09:36:23"
}
]
}
Create a new page., (*11)
POST /admin/api/pages
Request Body, (*12)
| Parameter | Required | Type | Description |
|---|---|---|---|
title |
Yes | string |
The page title |
template |
Yes | string |
The name of the template that should be applied to this page. |
is_stand_alone |
Yes | boolean |
If false, the page will not appear in any navigation and will only be accessible via a direct link. |
is_published |
Yes | boolean |
Whether the page is ready to be made public. |
parent_id |
No | int |
The ID of a page to nest this one under. |
slug |
No | string |
A URL-friendly identifier. Will be used as part of the final public-facing URL to the page. |
Example Response, (*13)
Returns the newly created page. See single page response example., (*14)
Get the details of a specific page., (*15)
GET /admin/api/pages/{id}
Request Body, (*16)
None, (*17)
Example Response, (*18)
{
"data": {
"id": 2,
"title": "A sub page",
"slug": "a-sub-page",
"uri": "a-root-page/a-sub-page",
"has_fixed_uri": true,
"parent_id": 1,
"template": "default",
"has_fixed_template": true,
"contents": [
{
"id": 2,
"key": "content",
"value": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium."
}
],
"media": [
{
"id": 1,
"folder_id": null,
"name": "Image",
"file_name": "image.jpg",
"disk": "public",
"mime_type": "image/jpeg",
"size": 102400,
"group": "image",
"created_at": "2018-12-25 10:15:12",
"updated_at": "2018-12-25 10:15:12"
}
],
"children_count": 0,
"is_stand_alone": false,
"is_published": true,
"is_deletable": true,
"created_at": "2019-02-19 09:36:23",
"updated_at": "2019-02-19 09:36:23"
}
}
Update the details of a specific page., (*19)
PATCH /admin/api/pages/{id}
Request Body, (*20)
| Parameter | Required | Type | Description |
|---|---|---|---|
title |
Yes | string |
The page title |
template |
Yes | string |
The name of the template that should be applied to this page. |
is_stand_alone |
Yes | boolean |
If false, the page will not appear in any navigation and will only be accessible via a direct link. |
is_published |
Yes | boolean |
Whether the page is ready to be made public. |
parent_id |
No | int |
The ID of a page to nest this one under. |
slug |
No | string |
A URL-friendly identifier. Will be used as part of the final public-facing URL to the page. |
Example Response, (*21)
Returns the updated page. See single page response example., (*22)
Delete a specific page., (*23)
DELETE /admin/api/pages/{id}
Request Body, (*24)
None, (*25)
Example Response, (*26)
The HTTP status code will be 204 if successful., (*27)
List all available templates., (*28)
GET /admin/api/page-templates
Request Body, (*29)
None, (*30)
Example Response, (*31)
{
"data": [
{
"name": "home",
"label": "Home"
},
{
"name": "default",
"label": "Default"
}
]
}
use Optimus\Pages\Template;
use Illuminate\Http\Request;
use Optimus\Pages\Models\Page;
class DefaultTemplate extends Template
{
public function name(): string
{
return 'default';
}
public function label(): string
{
return 'A custom label';
}
public function validate(Request $request)
{
$request->validate([
'content' => 'required'
]);
}
public function save(Page $page, Request $request)
{
$page->addContents([
'content' => $request->input('content')
]);
$page->attachMedia($request->input('media_id'));
}
}
use Optimus\Pages\Facades\Template;
// Get all the registered templates...
Template::all();
// Get the template with the given name...
Template::find($name);
// Register a template...
Template::register(new DefaultTemplate);
// Register multiple templates...
Template::registerMany([
new HomeTemplate,
new ContactTemplate
]);
The MIT License (MIT). Please see License File for more information., (*32)
MIT
MIT