1. Go to this page and download the library: Download qeezer/api-responder 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/ */
qeezer / api-responder example snippets
namespace App\Controllers;
use QeeZer\ApiResponder\ResponderFactory;
use Request;
use App\Models\User;
class IndexController
{
public function index(Request $request)
{
return ResponderFactory::responseSuccess();
}
public function item(Request $request)
{
return ResponderFactory::responseItem(User::find(1));
}
public function collection(Request $request)
{
return ResponderFactory::responseCollection(User::all());
}
public function paginate(Request $request)
{
return ResponderFactory::responsePaginate(User::simplePaginate(10));
}
public function data(Request $request)
{
return ResponderFactory::responseData([
'is_can' => true,
'name' => 'Tom',
]);
}
public function collection(Request $request)
{
if (!$request->user()) {
return ResponderFactory::responseUnauthorized();
}
return ResponderFactory::responseItem($request->user());
}
}
namespace App\Controllers;
use QeeZer\ApiResponder\Responder;
use Request;
class BaseController
{
use Responder;
}
namespace App\Controllers;
use QeeZer\ApiResponder\Responder;
use Request;
class IndexController extends BaseController
{
public function index(Request $request)
{
return $this->responseSuccess();
}
}
namespace App\Resources;
use QeeZer\ApiResponder\DefaultResource;
class UserResource extends DefaultResource
{
public function toArray(): array
{
return [
'id' => $this->data['id'],
'name' => $this->data['name'],
'phone' => $this->data['mobile'],
];
}
}
namespace App\Controllers;
use App\Models\User;
use App\Resources\UserResource;
use QeeZer\ApiResponder\Responder;
use Request;
class IndexController extends BaseController
{
public function detail(Request $request)
{
$data = $this->validata([
'uid' => '