index.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. {{--
  2. Вьюха: Список автомобилей с фильтрами и пагинацией
  3. Создана: 2026-05-06
  4. Контроллер: Admin\CarController::index()
  5. Переменные: $cars (LengthAwarePaginator), $makes, $platforms — для фильтров
  6. --}}
  7. @extends('admin.layout')
  8. @section('title', 'Автомобили')
  9. @section('content_header')
  10. <div class="d-flex justify-content-between align-items-center">
  11. <h1 class="m-0">Автомобили</h1>
  12. <a href="{{ route('admin.cars.create') }}" class="btn btn-primary btn-sm">
  13. <i class="fas fa-plus"></i> Добавить
  14. </a>
  15. </div>
  16. @stop
  17. @section('breadcrumb')
  18. <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">Главная</a></li>
  19. <li class="breadcrumb-item active">Автомобили</li>
  20. @stop
  21. @section('content')
  22. @if(session('success'))
  23. <div class="alert alert-success alert-dismissible">
  24. <button type="button" class="close" data-dismiss="alert">&times;</button>
  25. {{ session('success') }}
  26. </div>
  27. @endif
  28. @php
  29. // Базовые параметры фильтра (без platform и page) — для построения URL кнопок площадок
  30. $baseParams = array_filter(
  31. request()->only(['q', 'status', 'condition', 'make']),
  32. fn($v) => $v !== null && $v !== ''
  33. );
  34. $activePlatform = request('platform', '');
  35. @endphp
  36. {{-- Быстрый фильтр по площадкам — кнопки из справочника --}}
  37. @if($platforms->isNotEmpty())
  38. <div class="mb-3 d-flex flex-wrap align-items-center" style="gap:6px">
  39. <span class="text-muted small mr-1"><i class="fas fa-map-marker-alt"></i> Площадка:</span>
  40. <a href="{{ route('admin.cars.index', $baseParams) }}"
  41. class="btn btn-sm {{ $activePlatform === '' ? 'btn-primary' : 'btn-outline-secondary' }}">
  42. Все
  43. </a>
  44. @foreach($platforms as $platform)
  45. <a href="{{ route('admin.cars.index', array_merge($baseParams, ['platform' => $platform])) }}"
  46. class="btn btn-sm {{ $activePlatform === $platform ? 'btn-primary' : 'btn-outline-secondary' }}">
  47. {{ $platform }}
  48. </a>
  49. @endforeach
  50. @if($activePlatform !== '')
  51. <a href="{{ route('admin.cars.index', $baseParams) }}" class="btn btn-sm btn-link text-danger p-0 ml-1">
  52. <i class="fas fa-times"></i> сбросить
  53. </a>
  54. @endif
  55. </div>
  56. @endif
  57. {{-- Фильтры (поиск + остальные поля) --}}
  58. <div class="card card-outline card-secondary mb-3">
  59. <div class="card-header">
  60. <h3 class="card-title"><i class="fas fa-filter mr-1"></i> Фильтры</h3>
  61. <div class="card-tools">
  62. <button type="button" class="btn btn-tool" data-card-widget="collapse">
  63. <i class="fas fa-minus"></i>
  64. </button>
  65. </div>
  66. </div>
  67. <div class="card-body">
  68. <form method="GET" action="{{ route('admin.cars.index') }}">
  69. @if($activePlatform)
  70. <input type="hidden" name="platform" value="{{ $activePlatform }}">
  71. @endif
  72. <div class="row">
  73. <div class="col-md-4">
  74. <div class="form-group mb-2">
  75. <input type="text" name="q" class="form-control form-control-sm"
  76. placeholder="Марка, модель, VIN, заголовок..." value="{{ request('q') }}">
  77. </div>
  78. </div>
  79. <div class="col-md-2">
  80. <div class="form-group mb-2">
  81. <select name="status" class="form-control form-control-sm">
  82. <option value="">Статус</option>
  83. <option value="active" @selected(request('status') === 'active')>Активен</option>
  84. <option value="sold" @selected(request('status') === 'sold')>Продан</option>
  85. <option value="draft" @selected(request('status') === 'draft')>Черновик</option>
  86. </select>
  87. </div>
  88. </div>
  89. <div class="col-md-2">
  90. <div class="form-group mb-2">
  91. <select name="condition" class="form-control form-control-sm">
  92. <option value="">Состояние</option>
  93. <option value="new" @selected(request('condition') === 'new')>Новый</option>
  94. <option value="used" @selected(request('condition') === 'used')>Б/У</option>
  95. </select>
  96. </div>
  97. </div>
  98. <div class="col-md-2">
  99. <div class="form-group mb-2">
  100. <select name="make" class="form-control form-control-sm">
  101. <option value="">Марка</option>
  102. @foreach($makes as $make)
  103. <option value="{{ $make }}" @selected(request('make') === $make)>{{ $make }}</option>
  104. @endforeach
  105. </select>
  106. </div>
  107. </div>
  108. <div class="col-md-2">
  109. <div class="d-flex gap-2">
  110. <button type="submit" class="btn btn-primary btn-sm">
  111. <i class="fas fa-search"></i> Найти
  112. </button>
  113. <a href="{{ route('admin.cars.index') }}" class="btn btn-default btn-sm ml-1">
  114. <i class="fas fa-times"></i>
  115. </a>
  116. </div>
  117. </div>
  118. </div>
  119. </form>
  120. </div>
  121. </div>
  122. {{-- Таблица --}}
  123. <div class="card">
  124. <div class="card-body p-0">
  125. <table class="table table-hover table-sm mb-0">
  126. <thead>
  127. <tr>
  128. <th style="width:50px">ID</th>
  129. <th style="width:60px">Фото</th>
  130. <th>Марка / Модель</th>
  131. <th>Год</th>
  132. <th>Площадка</th>
  133. <th>Статус</th>
  134. <th>Состояние</th>
  135. <th>Цена (₽)</th>
  136. <th>Пробег</th>
  137. <th style="width:100px">Действия</th>
  138. </tr>
  139. </thead>
  140. <tbody>
  141. @forelse($cars as $car)
  142. <tr>
  143. <td>{{ $car->id }}</td>
  144. <td>
  145. @if($car->photo_main)
  146. <img src="{{ Storage::url($car->photo_main) }}"
  147. class="img-thumbnail" style="width:48px;height:36px;object-fit:cover;">
  148. @else
  149. <div class="bg-light text-center" style="width:48px;height:36px;line-height:36px;font-size:10px;color:#aaa">
  150. <i class="fas fa-car"></i>
  151. </div>
  152. @endif
  153. </td>
  154. <td>
  155. <a href="{{ route('admin.cars.edit', $car) }}">
  156. {{ $car->make }} {{ $car->model }}
  157. </a>
  158. @if($car->generation)
  159. <small class="text-muted">{{ $car->generation }}</small>
  160. @endif
  161. </td>
  162. <td>{{ $car->year }}</td>
  163. <td>
  164. @if($car->platform)
  165. <span class="badge badge-light border">{{ $car->platform }}</span>
  166. @else
  167. <span class="text-muted">—</span>
  168. @endif
  169. </td>
  170. <td>
  171. @php
  172. $badge = match($car->status) {
  173. 'active' => 'success',
  174. 'sold' => 'secondary',
  175. 'draft' => 'warning',
  176. default => 'light',
  177. };
  178. @endphp
  179. <span class="badge badge-{{ $badge }}">{{ $car->status_label }}</span>
  180. </td>
  181. <td>{{ $car->condition_label }}</td>
  182. <td>{{ $car->price_rub ? number_format($car->price_rub, 0, '.', ' ') : '—' }}</td>
  183. <td>{{ $car->mileage_km ? number_format($car->mileage_km, 0, '.', ' ') . ' км' : '—' }}</td>
  184. <td>
  185. <a href="{{ route('admin.cars.edit', $car) }}"
  186. class="btn btn-xs btn-info" title="Редактировать">
  187. <i class="fas fa-edit"></i>
  188. </a>
  189. <form action="{{ route('admin.cars.destroy', $car) }}" method="POST"
  190. class="d-inline"
  191. onsubmit="return confirm('Удалить автомобиль?')">
  192. @csrf @method('DELETE')
  193. <button class="btn btn-xs btn-danger" title="Удалить">
  194. <i class="fas fa-trash"></i>
  195. </button>
  196. </form>
  197. </td>
  198. </tr>
  199. @empty
  200. <tr>
  201. <td colspan="10" class="text-center text-muted py-4">
  202. Автомобили не найдены.
  203. <a href="{{ route('admin.cars.create') }}">Добавить первый</a>
  204. </td>
  205. </tr>
  206. @endforelse
  207. </tbody>
  208. </table>
  209. </div>
  210. @if($cars->hasPages())
  211. <div class="card-footer">
  212. {{ $cars->links() }}
  213. </div>
  214. @endif
  215. </div>
  216. @stop
  217. @section('plugins.Select2', true)