目录文件下新建一个BaseConttoller控制器
<?php namespace App\Http\Controllers\Task\Task13; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class BaseConttoller extends Controller { // public function getJsonData($code, $message, $data){ $json=[ 'code'=>$code, 'message'=>$message, 'data'=>!empty($data)?$data:[], ]; return response()->json($json); } }
控制器继承并调用: