| Conditions | 5 |
| Paths | 2 |
| Total Lines | 31 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public function handle($request, Closure $next) |
||
| 12 | { |
||
| 13 | //check for database connection every 5 minutes |
||
| 14 | $time = now()->addMinutes(5); |
||
| 15 | $error = null; |
||
| 16 | |||
| 17 | //dev |
||
| 18 | // cache()->forget('check'); |
||
| 19 | |||
| 20 | if (!Cache::has('check')) { |
||
| 21 | Cache::remember('check', $time, function () use ($error) { |
||
| 22 | try { |
||
| 23 | DB::connection()->table(DB::raw('settings'))->first([DB::raw(1)]); |
||
| 24 | if (!DB::connection()->table(DB::raw('settings'))->count()) { |
||
| 25 | $error = __('api.db_data'); |
||
| 26 | } |
||
| 27 | } catch (\PDOException $e) { |
||
| 28 | $error = __('api.db_connect'); |
||
| 29 | } |
||
| 30 | |||
| 31 | //show error |
||
| 32 | if (isset($error)) { |
||
| 33 | cache()->forget('check'); |
||
| 34 | dd($error); |
||
| 35 | } |
||
| 36 | |||
| 37 | return true; |
||
| 38 | }); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $next($request); |
||
| 42 | } |
||
| 44 |