PHP code example of dwivedianuj9118 / laravel-api-starter
1. Go to this page and download the library: Download dwivedianuj9118/laravel-api-starter 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/ */
dwivedianuj9118 / laravel-api-starter example snippets
use Dwivedianuj9118\ApiStarter\Exceptions\ApiExceptionHandler;
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->render(function (Throwable $e, $request) {
if ($request->is('api/*')) {
return ApiExceptionHandler::handle($e);
}
});
});
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Http\Request;
public function boot(): void
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(
config('api-starter.rate_limit.per_minute')
)->by($request->ip());
});
}
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use HasApiTokens;
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims(): array
{
return [];
}
}