1. Go to this page and download the library: Download cyd622/laravel-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/ */
namespace App\Http\Resources;
use App\Traits\PaginatedCollection;
use Illuminate\Http\Resources\Json\JsonResource;
class Company extends JsonResource
{
use PaginatedCollection;
}
use LaravelApi\Response\ExceptionReport;
public function render($request, Exception $exception)
{
// 将方法拦截到自己的ExceptionReport
$reporter = ExceptionReport::make($exception);
if ($reporter->shouldReturn()) {
return $reporter->report();
}
return parent::render($request, $exception);
}
class User extends Authenticatable implements JWTSubject
{
...
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
}