PHP code example of everalan / api

1. Go to this page and download the library: Download everalan/api 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/ */

    

everalan / api example snippets


use Everalan\Api\Helpers;

class UserController extends Controller
{
    use Helpers;
    public function show(Request $request, $id)
    {
        $user = User::findOrFail($id);
        return $this->response()->item($user, new UserTransformer());
    }
}

$users = User::all();
return $this->response()->collection($users, new UserTransformer());

$users = User::paginate();
return $this->response()->paginator($users, new UserTransformer());

$out = [1, 2, 3, 4];
return $this->response()->array($out);

return $this->response()->success();
return $this->response()->accepted();
return $this->response()->created();
return $this->response()->noContent();
return $this->response()->error(403, '没有权限访问');


Route::group([
        'middleware' => ['guard:api'],
    ], function($api) {
    //不需要登录的接口
    $api->get('/login', 'UserController@login');

    $api->group([
        'middleware'    =>  ['auth.api'],
    ], function ($api) {
        //需要登录的接口
    });
});

$this->response()->