# Installation

# Requirements

  • PHP: ^7.4|^8.0
  • Laravel: ^8.0

# Installation

Require this package in the composer.json of your Laravel project. This will download the package and its dependent packages.

We also recommend you install our testing package as a development dependency. This adds test helpers as described in the Testing Chapter.

Install both packages using Composer (opens new window).

As we are currently on alpha releases, you will need to set your project's minimum stability to alpha (or dev) before installing our packages:

composer config minimum-stability alpha

Then install the packages:

composer require laravel-json-api/laravel
composer require --dev laravel-json-api/testing

The LaravelJsonApi\Laravel\ServiceProvider is auto-discovered and registered by default.

# Facades

Two facades are also auto-discovered:

  • LaravelJsonApi\Core\Facades\JsonApi
  • LaravelJsonApi\Laravel\Facades\JsonApiRoute

# Configuration

Publish the package configuration using the following Artisan command:

php artisan vendor:publish --provider="LaravelJsonApi\Laravel\ServiceProvider"

This will create a config/jsonapi.php file.

# Exception Handler

To ensure that clients receive a JSON:API error response for exceptions thrown by your application, you need to add the package exception renderer to your application's exception handler.

Update the register() method on your \App\Exceptions\Handler class as follows:

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
    // ...

     * Register the exception handling callbacks for the application.
     * @return void
    public function register()

For more information on exception parsing, see the error handling chapter.

Last Updated: 2/5/2021, 12:29:28 PM