Skip to content

Commit 68d2a5f

Browse files
authored
Update LaravelReadme.md
1 parent d0bd30b commit 68d2a5f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

LaravelReadme.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
```

0 commit comments

Comments
 (0)