Download the PHP package cyd622/laravel-api without Composer

On this page you can find all versions of the php package cyd622/laravel-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api

Laravel开发API助手

Software license Build dependencies stars php mysql laravel Latest Version Monthly Downloads

Laravel开发API助手

[将Laravel框架进行一些配置处理,让其在开发API时更得心应手]


背景

随着前后端完全分离,PHP也基本告别了view模板嵌套开发,转而专门写资源接口。Laravel是PHP框架中最优雅的框架,国内也越来越多人告别ThinkPHP选择了Laravel。Laravel框架本身对API有支持,但是感觉再工作中还是需要再做一些处理。Lumen用起来不顺手,有些包不能很好地支持。所以,将Laravel框架进行一些配置处理,让其在开发API时更得心应手。


环境和程序要求

程序 版本
PHP >= 7.1
MySQL >= 5.5
laravel/laravel >= 5.5
tymon/jwt-auth 1.0.0-rc.4.*

功能

  • [x] 统一Response响应处理
  • [x] Laravel Api-Resource资源 分页返回统一响应
  • [x] jwt-auth用户认证与无感知自动刷新
  • [x] jwt-auth多角色认证不串号
  • [x] 单一设备登陆
  • [x] 异常捕获,http状态码统一

安装


使用

添加服务提供商

2.发布配置文件

此命令会在 config 目录下生成一个 laravel_api.php 配置文件,你可以在此进行自定义配置。

  • response 是配置资源响应格式
  • exception 是配置需要拦截的异常

1.统一Response响应处理

所有请求都返回json格式,返回字段格式也是统一标准化 格式如下

默认success返回的http状态码是200error返回的状态码是400

  1. 新建Api控制器基类 或者 继承Api控制器基类
  2. use ApiResponse;
  3. 代码使用

4.返回

2.Api-Resource资源 分页返回统一响应

  1. 在Resource资源文件中引入
  2. use PaginatedCollection; 示例代码

3.使用示例

4.返回同上成功返回示例

关于分页返回的字段,你可以在配置文件中指定:config('laravel_api.response.page_info') 默认是current_pagelast_pageper_pagetotal 4个

3.异常自定义处理

1.修改 app/Exceptions 目录下的 Handler.php 文件

2.可自定义错误的异常设置 配置文件laravel_api.php,在exception.do_report加入需要拦截的异常,示例:

4.jwt-auth

jwt-auth的详细介绍分析可以看 JWT超详细分析 这篇文章,具体使用可以看 JWT完整使用详解 这篇文章。

1.打开 config 目录下的 app.php文件,添加服务提供者

2.发布配置文件

此命令会在 config 目录下生成一个 jwt.php 配置文件,你可以在此进行自定义配置。

3.生成密钥

此命令会在你的 .env 文件中新增一行 JWT_SECRET=secret。以此来作为加密时使用的秘钥。

4.配置 Auth guard. 打开 config 目录下的 auth.php文件,修改api的驱动为jwt。这样,我们就能让api的用户认证变成使用jwt。

5.更改 User Model 如果需要使用jwt-auth作为用户认证,我们需要对我们的 User模型进行一点小小的改变,实现一个接口,变更后的User模型如下

5.自动刷新用户认证 && 多看守器不串号 && 单一设备登陆

现在我想用户登录后,为了保证安全性,每个小时该用户的token都会自动刷新为全新的,用旧的token请求不会通过。我们知道,用户如果token不对,就会退到当前界面重新登录来获得新的token,我同时希望虽然刷新了token,但是能否不要重新登录,就算重新登录也是一周甚至一个月之后呢?给用户一种无感知的体验。

1.增加中间件别名 打开 app/Http 目录下的 Kernel.php 文件,添加如下一行

2.路由器修改

3.登录控制器引入LoginActionTrait

4.原理


All versions of laravel-api with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
tymon/jwt-auth Version 1.0.0-rc.4.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cyd622/laravel-api contains the following files

Loading the files please wait ....