PHP code example of nickjbedford / laravel-endpoints
1. Go to this page and download the library: Download nickjbedford/laravel-endpoints 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/ */
nickjbedford / laravel-endpoints example snippets
class UsersEndpoint extends YetAnother\Laravel\Endpoint
{
// Specify the URI of the endpoint.
protected string $uri = '/users';
// Specify the route prefix for the endpoint methods.
// The suffixes are get, post, update and delete.
protected string $routePrefix = 'users.';
// Register the following methods when set to true.
protected bool $get = true;
protected bool $post = true;
protected bool $update = true;
protected bool $delete = true;
/**
* Override the GET method.
* @param Request $request
* @return Response
*/
function get(Request $request): Response
{
$users = /* fetch user(s) */;
return $this->success($users);
}
/**
* Override the POST method.
* @param Request $request
* @return Response
*/
function post(Request $request): Response
{
$user = /* create new user */;
return $this->success($user);
}
/**
* Override the PATCH method.
* @param Request $request
* @return Response
*/
function update(Request $request): Response
{
$user = /** fetch and update user */
return $this->success(self::UpdateResponse);
}
/**
* Override the DELETE method.
* @param Request $request
* @return Response
*/
function delete(Request $request): Response
{
/** fetch and delete user */
return $this->success(self::DeleteResponse);
}
}