PHP code example of flarum / json-api-server
1. Go to this page and download the library: Download flarum/json-api-server 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/ */
flarum / json-api-server example snippets
use App\Models\User;
use Tobyz\JsonApiServer\Laravel;
use Tobyz\JsonApiServer\Laravel\EloquentResource;
use Tobyz\JsonApiServer\Laravel\Filter;
use Tobyz\JsonApiServer\Endpoint;
use Tobyz\JsonApiServer\Schema\Field;
use Tobyz\JsonApiServer\Schema\Type;
use Tobyz\JsonApiServer\JsonApi;
class UsersResource extends EloquentResource
{
public function type(): string
{
return 'users';
}
public function newModel(Context $context): object
{
return new User();
}
public function endpoints(): array
{
return [
Endpoint\Show::make(),
Endpoint\Index::make()->paginate(),
Endpoint\Create::make()->visible(Laravel\can('create')),
Endpoint\Update::make()->visible(Laravel\can('update')),
Endpoint\Delete::make()->visible(Laravel\can('delete')),
];
}
public function fields(): array
{
return [
Field\Attribute::make('name')
->type(Type\Str::make())
->writable()
->