Skip to content

Instantly share code, notes, and snippets.

View developerdino's full-sized avatar

Dean Tedesco developerdino

  • Verified International @verifedit
  • Melbourne, Australia
  • 19:42 (UTC +10:00)
  • X @developerdino
View GitHub Profile
{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
}
}
<?php
namespace App\Http\Controllers;
use App\Article;
use App\Http\Resources\ArticleResource;
use App\Http\Resources\ArticlesResource;
use Illuminate\Http\Request;
class ArticleController extends Controller
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
}
}
}
<?php
Route::resource('articles', 'ArticleController');
<?php
class ArticleController
{
/**
* Display the specified resource.
*
* @param \App\Article $article
*
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class ArticleResource extends Resource
{
/**
* Transform the resource into an array.
@developerdino
developerdino / CreateCommentsTable.php
Last active September 7, 2017 01:22
Using Laravel 5.5 Resources to create your own {JSON:API} formatted API - Medium Gists
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
@developerdino
developerdino / CreateArticleTable.php
Last active September 7, 2017 01:21
Using Laravel 5.5 Resources to create your own {JSON:API} formatted API - Medium Gists
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
@developerdino
developerdino / CreatePeopleTable.php
Last active September 7, 2017 01:20
Using Laravel 5.5 Resources to create your own {JSON:API} formatted API - Medium Gists
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePeopleTable extends Migration
{
/**
* Run the migrations.
@developerdino
developerdino / jsonapi-org-example.json
Created September 6, 2017 10:15
Using Laravel 5.5 Resources to create your own {JSON:API} formatted API - Medium Gists
{
"links": {
"self": "http://example.com/articles",
"next": "http://example.com/articles?page[offset]=2",
"last": "http://example.com/articles?page[offset]=10"
},
"data": [{
"type": "articles",
"id": "1",
"attributes": {