jasonc/api

3.5.2 2021-06-10 01:36 UTC

README

快速构建laravel api服务

1.安装

$ composer require jasonc/api

$ php artisan api:install

$ php artisan vendor:publish

2.使用

return $this->message(string $message);
return $this->success(array $data);
return $this->failed(string $error);

3.修改 App\Exceptions\Handler 文件,引入Trait

<?php

namespace App\Exceptions;

use Jason\Api\Traits\ApiException;

class Handler extends ExceptionHandler
{

    use ApiException;
}

4.身份认证

修改User模型

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Jason\Api\Traits\ApiGuardable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject 
{

    use ApiGuardable;
}