1. Go to this page and download the library: Download echo-it/laravel-jsonapi 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/ */
namespace App\Http\Controllers;
use EchoIt\JsonApi\Request as ApiRequest;
use EchoIt\JsonApi\ErrorResponse as ApiErrorResponse;
use EchoIt\JsonApi\Exception as ApiException;
use Request;
class ApiController extends Controller
{
public function handleRequest($modelName, $id = null)
{
/**
* Create handler name from model name
* @var string
*/
$handlerClass = 'App\\Handlers\\' . ucfirst($modelName) . 'Handler';
if (class_exists($handlerClass)) {
$url = Request::url();
$method = Request::method();
$id, $content, $
namespace App\Handlers;
use Symfony\Component\HttpFoundation\Response;
use App\Models\User;
use EchoIt\JsonApi\Exception as ApiException;
use EchoIt\JsonApi\Request as ApiRequest;
use EchoIt\JsonApi\Handler as ApiHandler;
use Request;
/**
* Handles API requests for Users.
*/
class UsersHandler extends ApiHandler
{
const ERROR_SCOPE = 1024;
/*
* List of relations that can be t GET functionality, or override with your own
return $this->handleGetDefault($request, new User);
}
/**
* Handles PUT requests.
* @param EchoIt\JsonApi\Request $request
* @return EchoIt\JsonApi\Model|Illuminate\Support\Collection|EchoIt\JsonApi\Response
*/
public function handlePut(ApiRequest $request)
{
//you can use the default PUT functionality, or override with your own
return $this->handlePutDefault($request, new User);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.