| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | public static function valid($rules = [], string $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 | respondWith(redirect()->back()->with(['message' => implode('<br/>', $message), 'message_type' => 'warning'])->withInput()); |
||
| 21 | } |
||
| 22 | $result = [ |
||
| 23 | 'api_status' => 0, |
||
| 24 | 'api_message' => implode(', ', $message), |
||
| 25 | ]; |
||
| 26 | respondWith()->json($result, 200); |
||
| 27 | } |
||
| 28 | } |