PHP code example of anxis / laravel-json-api-resource
1. Go to this page and download the library: Download anxis/laravel-json-api-resource library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anxis / laravel-json-api-resource example snippets
namespace App\Http\Controllers;
use App\User;
use Kharysharpe\LaravelJsonApiResource\Http\Resource\JsonApi\Resource;
use Kharysharpe\LaravelJsonApiResource\Http\Resource\JsonApi\ResourceCollection;
class UserController extends Controller
{
public function index()
{
$user = User::all();
return new ResourceCollection($user);
}
public function show($id)
{
$user = User::find($id);
return new Resource($user);
}
}
namespace App\Http\Controllers;
use App\User;
use App\Http\Resource\UserCollection;
use App\Http\Resource\UserResource;
class UserController extends Controller
{
public function index()
{
$user = User::all();
return new UserCollection($user);
}
public function show($id)
{
$user = User::find($id);
return new UserResource($user);
}
}
namespace App\Http\Resource;
use Kharysharpe\LaravelJsonApiResource\Http\Resource\JsonApi\Resource;
class UserResource extends Resource
{
//
}
namespace App\Http\Resource;
use Kharysharpe\LaravelJsonApiResource\Http\Resource\JsonApi\ResourceCollection;
class UserCollection extends ResourceCollection
{
}
php artisan migrate
php artisan serve
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.