mezon/crud-service

Small crud-service script

1.2.3 2022-06-20 17:10 UTC

This package is auto-updated.

Last update: 2024-11-20 22:57:31 UTC


README

Open Collective Build Status codecov

Installation

Just print in console

composer require mezon/crud-service

And that's all )

First steps

Now we are ready to create out first CRUD service. Here it is:

/**
 * Service class
 */
class TodoService extends \Mezon\CrudService\CrudService
{

    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct([
            'fields' => [
                'id' => [
                    'type' => 'integer'
                ],
                'title' => [
                    'type' => 'string'
                ]
            ],
            'table-name' => 'records',
            'entity-name' => 'record'
        ]);
    }
}

$service = new TodoService();
$service->run();

The main part of this listing is:

parent::__construct([
	'fields' => [
		'id' => [
			'type' => 'integer'
		],
		'title' => [
			'type' => 'string'
		]
	],
	'table-name' => 'records',
	'entity-name' => 'record'
]);

Here we describe a list of fields of our entity, table name where it is stored and entity name.

Default endpoints

Out of the box a list of CRUD endpoints are available:

GET /list/
GET /all/ 
GET /exact/list/[il:ids]/
GET /exact/[i:id]/
GET /fields/
POST|PUT /delete/[i:id]/
POST|DELETE  /delete/
POST|PUT /create/
POST /update/[i:id]/
GET /new/from/[s:date]/
GET /records/count/
GET /last/[i:count]/
GET /records/count/[s:field]