jasonc / api
5.0.8
2022-12-08 04:32 UTC
Requires
- php: >=7.4.0|>=8.0
- laravel/framework: >8.0|>9.0
- laravel/sanctum: ^2.11
- symfony/http-foundation: ^6.0
- yangjisen/laravel-cache-provider: ^3.0
This package is auto-updated.
Last update: 2024-10-24 09:06:56 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; }