1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Base;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Arr;
- class BaseController extends Controller
- {
- /**
- * 不支持多维结构
- *
- * @param array $rules
- * @param array $messages
- * @param array $customAttributes
- * @return array
- */
- public function valid(array $rules, array $messages = [], array $customAttributes = []): array
- {
- $data = [];
- $validated = request()->validate($rules);
- foreach ($rules as $k => $v) {
- $data[$k] = Arr::get($validated, $k);
- }
- return $data;
- }
- public function ok($data = null)
- {
- return [
- "code" => 200,
- "data" => $data,
- ];
- }
- public function error(string $msg)
- {
- return [
- "code" => 400,
- "error" => $msg,
- ];
- }
- }
|