1. Go to this page and download the library: Download dscmall/laravel-json-rpc 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/ */
dscmall / laravel-json-rpc example snippets
use AvtoDev\JsonRPC\RpcRouter;
RpcRouter::on('please_sum_array_values', 'YourNamespace\\SomeController@sum');
RpcRouter::on('show_full_request', 'YourNamespace\\SomeController@showInfo');
use Illuminate\Support\Facades\Route;
Route::post('/rpc', 'AvtoDev\\JsonRpc\\Http\\Controllers\\RpcController');
namespace YourNamespace;
use AvtoDev\JsonRpc\Requests\RequestInterface;
class SomeController
{
/**
* Get sum of array.
*
* @param RequestInterface $request
*
* @return int
*/
public function sum(RequestInterface $request): int
{
return (int) \array_sum($request->getParams());
}
/**
* Get info from request.
*
* @param RequestInterface $request
*
* @return mixed[]
*/
public function showInfo(RequestInterface $request): array
{
return [
'params' => $request->getParams(),
'notification' => $request->isNotification(),
'method_name' => $request->getMethod(),
'request ID' => $request->getId(),
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.