PHP code example of pellerichard / laravel-dynamic-api
1. Go to this page and download the library: Download pellerichard/laravel-dynamic-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pellerichard / laravel-dynamic-api example snippets
use Pellerichard\LaravelDynamicApi\Services\Facades\ApiService;
// Create an entity.
ApiService::builder()
->setType(type: 'human')
->setAttributes(attributes: [
'first_name' => 'Richárd',
'last_name' => 'Pelle',
'age' => 23,
'occupation' => 'Full Stack Developer',
])
->create();
// Get all entities.
ApiService::builder()
->withPagination(withPagination: false)
->get();
// Get all entities with specific type.
ApiService::builder()
->whereType(type: 'human')
->withPagination(withPagination: false)
->get();
// Get one specific entity, and return it's data.
ApiService::builder()
->whereType(type: 'human')
->whereRecordId(recordId: 1)
->first();
// Update an entity.
ApiService::builder()
->whereType(type: 'human')
->whereRecordId(recordId: 1)
->setAttributes(attributes: [
'age' => 24,
'github_link' => 'https://github.com/pellerichard'
])
->update();
// Delete an entity.
ApiService::builder()
->whereType(type: 'human')
->whereRecordId(recordId: 1)
->delete();
return [
/*
|--------------------------------------------------------------------------
| Create Endpoints
|--------------------------------------------------------------------------
|
| If you wish to create the default endpoints set this value to true.
|
*/
'endpoints' => true,
/*
|--------------------------------------------------------------------------
| Endpoint Rules
|--------------------------------------------------------------------------
|
| Endpoints must be allowed in order for this functionality to take event.
| Prefix (Route prefix for instance: 'api/v1/dynamic-api/')
| Middleware (Route middleware which must pass in order to reach the endpoints, common example: ['api', 'web'])
|
*/
'endpoint_rules' => [
'prefix' => 'api/v1/dynamic-api/',
'middleware' => [],
],
];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.