Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
/ laravel-Cruddy Public archive

A really simple package that provides a CRUD JSON API for your Laravel 5 application..

License

Notifications You must be signed in to change notification settings

Askedio/laravel-Cruddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel-cruddy

A really simple package that provides a CRUD JSON API for your Laravel 5 application.

Build Status StyleCI Code Climate Codacy Badge Codacy Badge

Installation

Composer: require

composer require askedio/laravel-cruddy:dev-master

Providers: config/app.php

Add the Service Provider to your providers array.

'providers' => [
    Askedio\Laravel5ApiController\Providers\GenericServiceProvider::class,
        ...

Model: app/User.php

Add the traits to your Model to enable the Api and Search features. More Details & Options.

class User extends Authenticatable
{

    use \Askedio\Laravel5ApiController\Traits\ModelTrait;
    use \Askedio\Laravel5ApiController\Traits\SearchableTrait;
    ...

Controller: app/Http/Controllers/Api/UserController.php

Create a new controller for your API. More Details & Options.

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Routing\Controller as BaseController;

class UserController extends BaseController
{
    use \Askedio\Laravel5ApiController\Traits\ControllerTrait;
    public $modal = \App\User::class;
}

Routes: app/Http/routes.php

Create a prefixed group for your api and assign the api and jsonapi middleware. More Details & Options.

Route::group(['prefix' => 'api', 'middleware' => ['api', 'jsonapi']], function()
{
  Route::resource('user', 'Api\UserController');
});


Usage

Consume the API using Laravels resource routes, GET, PATCH, POST and DELETE. More Details & Options.

Example

GET /api/user/1
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": {
    "type": "users",
    "id": 1,
    "attributes": {
      "id": 1,
      "name": "Test User",
      "email": "[email protected]"
    }
  },
  "links": {
    "self": "/api/user/1"
  },
  "jsonapi": {
    "version": "1.0",
    "self": "v1"
  }
}



Comments

My goal is a plug-n-play json api for Laravel. You shouldn't need to configure much of anything to enable the api on your models but if you still want advanced features like relations, searching, etc, you get that too.

If you have any comments, opinions or can code review please reach me here or on twitter, @asked_io. You can also follow me on my website, asked.io.

Thank you.

-William

About

A really simple package that provides a CRUD JSON API for your Laravel 5 application..

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages