File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -91,4 +91,36 @@ class Handler extends ExceptionHandler
9191
9292```
9393
94- ** 注意:头请求未声明此次请求需要返回 json 数据时,` $this->fail($message, $err_code) ` 的错误码需要符合 http status_code 响应码**
94+ ## 控制器调用
95+
96+ ```
97+ <?php
98+
99+ namespace App\Http\Controllers;
100+
101+ use Illuminate\Http\Request;
102+
103+ class DemoController extends Controller
104+ {
105+ public function index()
106+ {
107+ // validate data
108+ \validator()->validate(\request(), [
109+ 'name' => 'required|string',
110+ 'age' => 'nullable|integer',
111+ ]);
112+
113+ // your business logic
114+ $error = false;
115+ if ($error) { // here business logic error.
116+ throw new \RuntimeException('error message');
117+ }
118+
119+ return $this->success([ // here response success
120+ 'key1' => 'value1',
121+ 'key2' => 'value2',
122+ ]);
123+ }
124+ }
125+
126+ ```
You can’t perform that action at this time.
0 commit comments