标签:数据 amp span 一个 tor support facade port info
<?php /** * Created by PhpStorm. * User: yly * Date: 2020/2/18 * Time: 17:48 */ namespace App\Http\Controllers\Tools; class ResponseLayout { //设置一个布尔类型,数据类型,信息类型,通过类型 public static function apply($bool = true, $data = [], $message = ‘‘, $pass = true) { $res = [];//定义一个空集合 $data && $res[‘data‘] = $data; if ($message) { $res[‘message‘] = $message; } else { $res[‘message‘] = $bool ? ‘操作成功!‘ : ‘操作失败!‘; } if ($pass) { header(‘Access-Control-Allow-Origin:*‘); } $res[‘status‘] = $bool ? 1 : 0; return response()->json($res); } }
<?php namespace App\Http\Controllers; use App\Http\Controllers\Tools\ResponseLayout; use Illuminate\Http\Request; use Illuminate\Support\Facades\Redis; class UserController extends Controller { //redis显示用户属性 public function user() { $data=\DB::table(‘user‘)->get(); return ResponseLayout::apply(true,$data,‘成功‘); } }
3.1用工具类的结果显示如下(显示包含调用成功的信息)
3.2不用工具类的返回结果(不包含返回信息)
标签:数据 amp span 一个 tor support facade port info
原文地址:https://www.cnblogs.com/yaoliuyang/p/12327606.html