Conditions | 3 |
Paths | 3 |
Total Lines | 19 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public static function valid($rules = [], $type = 'json') |
||
10 | { |
||
11 | $validator = Validator::make(request()->all(), $rules); |
||
12 | |||
13 | if (!$validator->fails()) { |
||
14 | return true; |
||
15 | } |
||
16 | |||
17 | $message = $validator->errors()->all(); |
||
18 | |||
19 | if ($type == 'json') { |
||
20 | $result = []; |
||
21 | $result['api_status'] = 0; |
||
22 | $result['api_message'] = implode(', ', $message); |
||
23 | sendAndTerminate(response()->json($result, 200)); |
||
|
|||
24 | } |
||
25 | |||
26 | $res = redirect()->back()->with(['message' => implode('<br/>', $message), 'message_type' => 'warning'])->withInput(); |
||
27 | sendAndTerminate($res); |
||
28 | } |
||
29 | } |