PHP code example of jack.savich / laravel-api-skeleton
1. Go to this page and download the library: Download jack.savich/laravel-api-skeleton 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/ */
jack.savich / laravel-api-skeleton example snippets
// on routes file
Route::group(['middleware' => 'api.auth'], function () {
// your routes ...
});
use Savich\ApiSkeleton\Controllers\ApiController;
use Savich\ApiSkeleton\Controllers\Mixins\TokenTrait;
use Savich\ApiSkeleton\Response\ResponseInterface;
class AuthController extends ApiController
{
use TokenTrait;
public function __construct(ResponseInterface $response)
{
parent::__construct($response);
}
/**
* API Login, on success return JWT Auth token
* @param LoginRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function login(LoginRequest $request) // you can make your own request
{
$user = $this->getUser($request->only('email', 'password'));
if (!$user) {
$this->addError('Invalid credentials');
return $this->send();
}
return $this->attemptToken($user);
}
}