Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Latest commit

 

History

History
215 lines (155 loc) · 4.96 KB

README.md

File metadata and controls

215 lines (155 loc) · 4.96 KB

JsonApi

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Infection MSI Total Downloads

This package is still in development !

Technologies

  • PHP 7.3+
  • PHPUnit 8.0+
  • Laravel 7.0+

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require-dev": {
        "vgirol/jsonapi": "dev-master"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplified by using the following command:

composer require vgirol/jsonapi

Registration

The package will automatically register itself.
If you're not using Package Discovery, add the Service Provider to your config/app.php file:

VGirol\JsonApi\JsonApiServiceProvider::class

Configuration

You have to publish the 2 config files with:

php artisan vendor:publish --provider="VGirol\JsonApi\JsonApiServiceProvider" --tag="config"

Usage

Quick start

Create Model, migration and seed.

// app/Models/Company.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    protected $table = 'xxx';
    protected $primaryKey = 'xxx';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'xxx'
    ];

    public function establishments()
    {
        return $this->hasMany('App\Models\Establishment', $this->getKeyName());
    }
}

For each model, create a form request extending VGirol\JsonApi\Requests\ResourceFormRequest abstract class.

// app/Http/Request/CompanyFormRequest.php

namespace App\Http\Requests;

use VGirol\JsonApi\Requests\ResourceFormRequest;

class CompanyFormRequest extends ResourceFormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            //
        ];
    }
}

Create route using Route::jsonApiResource macro.

// routes/api.php

Route::jsonApiResource(
    'companies',        // Route name
);

Publish the config files (jsonapi-alias.php and jsonapi.php).

php artisan vendor:publish --provider="VGirol\JsonApi\JsonApiServiceProvider" --tag="config"

Fill the jsonapi-alias.php config file.

// jsonapi-alias.php

return [

    'groups' => [
        [
            'type' => 'company',        // Resource type
            'route' => 'companies',     // Route name
            'model' => \App\Models\Company::class,
            'request' => \App\Http\Requests\CompanyFormRequest::class
        ],
        [
            //
        ]
    ]
];

That's all !

Documentation

A user guide can be found here.

The API documentation is available in XHTML format at the url http://jsonapi.girol.fr/docs/ref/index.html.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.