1. Go to this page and download the library: Download mleczek/laravel-rest 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/ */
class UserFilterContext
{
public function scoreAbove($query, $value)
{
// Validation of the $value argument...
$query->where('score', '>', $value);
}
}
response()->item($query);
return response()->item(User::query());
public function show()
{
$user = rest()->item(User::query());
$this->authorize('show', $user); // bad usage, see below solution
return response()->item($user);
}
public function show()
{
$user = User::first();
$this->authorize('show', $user);
return response()->item($user);
}
public function show()
{
$users = rest()->collection(User::query());
// Some operations goes here...
// $users->count - number of retrieved models [0,limit]
// $users->limit - max number of retrieved models
// $users->offset - number of skipped models
// $users->data - retrieved models
return response()->collections($users);
}