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

VGirol/JsonApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published