1. Go to this page and download the library: Download ebsp/resting 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/ */
ebsp / resting example snippets
class UserResource extends \Seier\Resting\Resource
{
public StringField $name;
public IntField $age;
public function __construct()
{
$this->name = new StringField();
$this->age = new IntField();
}
}
use Seier\Resting\Resource;
use Seier\Resting\Fields\IntField;
use Seier\Resting\Fields\StringField;
class UserResource extends Resource
{
public StringField $name;
public IntField $age;
public function __construct()
{
$this->name = (new StringField())->trim();
$this->age = (new IntField())->
Route::post('/users', function (Request $request) {
$user = (new UserResource())->set($request->all());
// Persist…
return $user;
});
return (new UserResource())->set($model->toArray());
return (new UserResource())->mapMany(
$users,
fn (UserResource $r, User $u) => $r->set($u->toArray()),
);
use function Seier\Resting\Validation\Predicates\whenEquals;
public function __construct()
{
$this->true));
}
class AnimalResource extends UnionResource
{
public function __construct()
{
parent::__construct('type', fn () => [
'cat' => new CatResource(),
'dog' => new DogResource(),
]);
}
}
$resource = (new DynamicResource())
->withField('name', new StringField())
->withField('count', new IntField());
use Seier\Resting\Support\OpenAPI;
$spec = (new OpenAPI(Route::getRoutes()))->toArray();
Route::post('/users', UserController::class)
->docs('Create a new user.')
->lists(UserResource::class);