laravel result api风格封装公共响应(response)函数

在app/Http/Controllers/Controller.php中封装响应函数响应api请求。

<?php
namespace App\Http\Controllers;
public function index(){
    $data = Group::query()->where('pid',null)->with('son')->get(['id','pid','name','admin_name','phone','remark']);
    foreach ($data as $key => $value){
        $data[$key]['son'] = $value->son;
    }
    return $this->success($data);
}