Download the PHP package lswl/laravel-api without Composer
On this page you can find all versions of the php package lswl/laravel-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-api
目录
- 安装配置
- 使用说明
- 快速使用
- 中间件
- 异常处理
- 使用路由服务提供者
- 控制器
- 模型
- 服务层
- 数据访问层
- 控制器
- 模型
- 普通模型
- 中间表模型
- 服务层
- 数据访问层
- 中间件
- 异常处理
- 服务提供者
- API服务提供者
- 契约服务提供者
- 路由服务提供者
- trait介绍
- RequestInfoTrait.php
- ResourceControllerTrait.php
- ResourceServiceTrait.php
- ResultThrowTrait.php
- UserInfoTrait.php
- 工具类介绍
- Agent.php
- SdlCache.php
- Token.php
- 快速使用
安装配置
使用以下命令安装:
发布文件[可选]:
使用说明
环境变量值参考:env
restful参考: restful
快速使用
- 安装
- 发布配置[可选]
- 注册中间件
- 继承异常处理程序
- 使用路由服务提供者
- 示例代码
中间件
- 必须注册全局中间件
Lswl\Api\Middleware\ParamsHandlerMiddleware
- 可选中间件查看 中间件列表
异常处理
- 修改
App\Exceptions\Handler
继承的方法为Lswl\Api\Handlers\ExceptionHandler
- 其他异常捕获重写父类
customResponse()
方法,内容参考response
使用路由服务提供者
- 修改
App\Providers\RouteServiceProvider
继承的方法为Lswl\Api\Providers\LswlRouteServiceProvider
- 路由服务提供者会自动扫描
routes
目录生成路由
示例代码
控制器
- 直接继承
Lswl\Api\Controllers\BaseController
模型
- 可选继承
Lswl\Api\Models\BaseModel
、Lswl\Api\Models\BasePivot
、Lswl\Api\Models\UserModel
、Lswl\Api\Models\VersionModel
服务层
- 直接继承
Lswl\Api\Services\BaseService
数据访问层
- 直接继承
Lswl\Api\Daos\BaseDao
控制器
需继承
Lswl\Api\Controllers\BaseController
- 可使用
Lswl\Api\Traits\RequestInfoTrait
里的参数 - 可使用
Lswl\Api\Traits\UserInfoTrait
里的参数、方法
模型
普通模型
需继承
Lswl\Api\Models\BaseModel
- 可使用
Lswl\Database\Traits\DatabaseTrait
里的方法
中间表模型
需继承
Lswl\Api\Models\BasePivot
- 可使用
Lswl\Database\Traits\DatabaseTrait
里的方法
服务层
需继承
Lswl\Api\Services\BaseService
- 可使用
Lswl\Api\Traits\RequestInfoTrait
里的参数 - 可使用
Lswl\Api\Traits\UserInfoTrait
里的参数、方法
数据访问层
需继承
Lswl\Api\Daos\BaseDao
- 可使用
Lswl\Api\Traits\DaoSelectTrait
方法
中间件
用法加粗为必须调用
中间件 | 别名 | 用法 | 需要实现的契约或继承模型 |
---|---|---|---|
Lswl\Api\Middleware\ParamsHandlerMiddleware |
lswl.params.handler |
参数处理 | --- |
Lswl\Api\Middleware\ConvertEmptyStringsToNullMiddleware |
lswl.convert.empty.strings.to.null |
转换空字符串为null | --- |
Lswl\Api\Middleware\TrimStringsMiddleware |
lswl.trim.strings |
清除字符串空格 | --- |
Lswl\Api\Middleware\RequestLockMiddleware |
lswl.request.lock |
请求锁定 | --- |
Lswl\Api\Middleware\RequestLogMiddleware |
lswl.request.log |
记录请求日志(debug) | --- |
Lswl\Api\Middleware\CheckVersionMiddleware |
lswl.check.version |
检测应用版本 | Lswl\Api\Contracts\VersionModelInterface Lswl\Api\Models\VersionModel |
Lswl\Api\Middleware\CheckSignatureMiddleware |
lswl.check.signature |
验证请求签名 | --- |
Lswl\Api\Middleware\CheckTokenMiddleware |
lswl.check.token |
检测token,设置用户数据 | Lswl\Api\Contracts\UserModelInterface Lswl\Api\Models\UserModel |
Lswl\Api\Middleware\CheckSdlMiddleware |
lswl.check.sdl |
单设备登录,需要复写 Lswl\Api\Handlers\ExceptionHandler->sdlHandler() |
--- |
异常处理
App\Exceptions\Handler
继承Lswl\Api\Handlers\ExceptionHandler
其他异常捕获调用父类
response()
方法并重写,参考Lswl\Api\Handlers\ExceptionHandler->response()
服务提供者
API服务提供者
Lswl\Api\Providers\LswlApiServiceProvider
- 注册路由中间件
- 注册命令
- 合并配置
- 发布文件
契约服务提供者
Lswl\Api\Providers\LswlContractServiceProvider
- 绑定契约
Lswl\Api\Contracts\RequestParamsInterface
实现 - 绑定契约
Lswl\Api\Contracts\AgentInterface
实现 - 绑定契约
Lswl\Api\Contracts\UserModelInterface
实现 - 绑定契约
Lswl\Api\Contracts\VersionModelInterface
实现
路由服务提供者
Lswl\Api\Providers\LswlRouteServiceProvider
默认不启用
- 注册
base_path('routes')
下面所有 php 文件到路由
trait介绍
RequestInfoTrait.php
Lswl\Api\Traits\RequestInfoTrait
请求信息绑定
使用类:
Lswl\Api\Controllers\BaseController
Lswl\Api\Services\BaseService
ResourceControllerTrait.php
Lswl\Api\Traits\ResourceControllerTrait
资源控制器 trait
ResourceServiceTrait.php
Lswl\Api\Traits\ResourceServiceTrait
资源服务 trait
ResultThrowTrait.php
Lswl\Api\Traits\ResultThrowTrait
异常抛出辅助
UserInfoTrait.php
Lswl\Api\Traits\UserInfoTrait
用户信息绑定
使用类:
Lswl\Api\Controllers\BaseController
Lswl\Api\Services\BaseService
工具类介绍
Agent.php
Lswl\Api\Utils\Agent
请求 Agent 类
SdlCache.php
Lswl\Api\Utils\SdlCache
单设备登录类
Token.php
Lswl\Api\Utils\Token
令牌相关类
All versions of laravel-api with dependencies
ext-mbstring Version *
ext-json Version *
ext-openssl Version *
lswl/sign Version ^1.0
lswl/laravel-support Version ^8.0
lswl/laravel-log Version ^8.0
lswl/laravel-database Version ^8.0
jenssegers/agent Version ^2.0