diff --git a/app/Http/Controllers/Admin/PriceController.php b/app/Http/Controllers/Admin/PriceController.php index f7a7d25..27a1404 100644 --- a/app/Http/Controllers/Admin/PriceController.php +++ b/app/Http/Controllers/Admin/PriceController.php @@ -20,19 +20,23 @@ class PriceController extends Controller public function list(Request $request) { $inputs = [ - 'isExport' => 0, - 'sort' => $request->input('sort', ''), - 'sort_type' => $request->input('sort_type', ''), - 'page' => $request->get('page', 1), - + 'isExport' => 0, + 'sort' => $request->input('sort', ''), // ソート対象カラム + 'sort_type' => $request->input('sort_type', ''), // 昇順/降順 + 'page' => $request->get('page', 1), ]; + + // Price::search 内で orderBy を反映させる $inputs['list'] = Price::search($inputs); + if ($inputs['list']->total() > 0 && $inputs['page'] > $inputs['list']->lastPage()) { return redirect()->route('prices'); } + return view('admin.prices.list', $inputs); } + public function add(Request $request) { $inputs = [ diff --git a/app/Models/Price.php b/app/Models/Price.php index 868a12d..cfd2e5d 100644 --- a/app/Models/Price.php +++ b/app/Models/Price.php @@ -41,33 +41,36 @@ class Price extends Model public static function search($inputs) { - $list = self::query(); - // 只有在sort是有效字段时才排序 + $query = self::query(); + + // 検索条件 $allowedSortColumns = [ - 'price_parkplaceid', - 'prine_name', - 'price_month', - 'park_id', - 'psection_id', - 'price_ptypeid', - 'user_categoryid', - 'pplace_id', - 'price' + 'price_parkplaceid', // 駐車場所ID + 'park_id', // 駐輪場ID + 'prine_name', // 商品名 + 'price_month', // 期間 + 'user_categoryid', // 利用者分類ID + 'price', // 駐輪料金(税込) + 'psection_id', // 車種区分ID + 'price_ptypeid', // 駐輪分類ID + 'pplace_id', // 駐車車室ID ]; - $sort_column = $inputs['sort'] ?? ''; - $sort_type = strtolower($inputs['sort_type'] ?? 'asc'); - if (in_array($sort_column, $allowedSortColumns)) { - if (!in_array($sort_type, ['asc', 'desc'])) { - $sort_type = 'asc'; + + // ソート指定 + $sortColumn = $inputs['sort'] ?? ''; + $sortType = strtolower($inputs['sort_type'] ?? 'asc'); + + if (in_array($sortColumn, $allowedSortColumns, true)) { + if (!in_array($sortType, ['asc', 'desc'], true)) { + $sortType = 'asc'; } - $list->orderBy($sort_column, $sort_type); + $query->orderBy($sortColumn, $sortType); } - if ($inputs['isExport']) { - $list = $list->get(); - } else { - $list = $list->paginate(Utils::item_per_page); - } - return $list; + + // データ取得 + return $inputs['isExport'] + ? $query->get() + : $query->paginate(\App\Utils::item_per_page ?? 20); } diff --git a/resources/views/admin/prices/_form.blade.php b/resources/views/admin/prices/_form.blade.php index 85e4e39..eeb60ed 100644 --- a/resources/views/admin/prices/_form.blade.php +++ b/resources/views/admin/prices/_form.blade.php @@ -6,138 +6,155 @@ @elseif(Session::has('error'))
-

{{__('誤差')}}:

+

{{ __('誤差') }}:

{!! Session::get('error') !!}
@elseif(isset($errorMsg))
-

{{__('誤差')}}:

+

{{ __('誤差') }}:

{!! $errorMsg !!}
@endif -
- @if($isInfo) - {{__('登録')}} - {{__('編集')}} - @else - - @endIf -
+
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
- -
-
-
- @if($isInfo) - {{__('登録')}} - {{__('編集')}} - @else - - @endIf -
+ @if($isEdit) + +
+ +
+
+
+ +
+
+ @endif + + +
+ +
+
+
+ +
+
+ + +
+ +
+
+
+ +
+
+ + + +
+ +
+
+
+ +
+
+ + +
+ +
+
+
+ +
+
+ + +
+ +
+
+
+ +
+
+ + +
+ +
+
+
+ +
+
+ + +
+ +
+
+
+ +
+
+ + + +
+ +
+ +
+
+ + + {{-- 下部ボタン --}} + @if($isEdit) + {{-- 編集画面 --}} + + +
+ @csrf + @method('DELETE') + +
+ @else + {{-- 新規画面 --}} + + @endif + + \ No newline at end of file diff --git a/resources/views/admin/prices/edit.blade.php b/resources/views/admin/prices/edit.blade.php index ee35a4b..2e037a0 100644 --- a/resources/views/admin/prices/edit.blade.php +++ b/resources/views/admin/prices/edit.blade.php @@ -1,28 +1,37 @@ - @extends('layouts.app') -@section('title', '[東京都|〇〇駐輪場] 駐輪場所、料金マスタ') +@section('title', '駐輪場所、料金マスタ') @section('content') - -
-
- +
+
+
+
+

編集

+
+ +
+
+
-
-
-
-
- - - - @include('admin.prices._form',['isEdit'=>1,'isInfo'=>0]) -
-
+
+
+
+
+
+
+ @csrf + @method('PUT') + @include('admin.prices._form', ['isEdit' => true]) +
-
-
- - +
+
@endsection diff --git a/resources/views/admin/prices/list.blade.php b/resources/views/admin/prices/list.blade.php index 23b3ec6..bb295d8 100644 --- a/resources/views/admin/prices/list.blade.php +++ b/resources/views/admin/prices/list.blade.php @@ -11,8 +11,7 @@
@@ -23,26 +22,31 @@ {{-- ▼ メインコンテンツ --}}
+ {{-- 並び替え用 hidden --}} +
+ @csrf + + +
- {{-- ▼ ボタン列(新規/削除/CSV出力/インポート/エクスポート) --}} + {{-- ▼ 各種アクションボタン群 --}}
- - - - -
- {{-- ▼ ページネーション(上部・右寄せ) --}} -
- {{ $list->appends(['sort' => $sort, 'sort_type' => $sort_type])->links('pagination') }} +
+ {{ $list->appends(['sort' => $sort ?? '', 'sort_type' => $sort_type ?? ''])->links('pagination') }}
- + {{-- ▼ フラッシュメッセージ --}}
@if(Session::has('success')) @@ -68,58 +72,77 @@ {{-- ▼ 一覧(市区マスタ準拠:1枚テーブル/先頭が「チェック+編集」統合列) --}}
@csrf -
- - - - {{-- 統合列:全選択チェック + 編集(背景 #faebd7) --}} - - {{-- データ列(見出しはそのまま) --}} - - - - - - - - - - - - - @foreach($list as $item) - - {{-- ▼ 統合セル:チェック + 編集(pk[]/背景 #faebd7/間隔は ml-2) --}} - + +
+
+ + @csrf +
- - - 駐車場所ID駐輪場ID商品名期間利用者分類ID駐輪料金(税込)車種区分ID駐輪分類ID駐車車室ID
- - {{__('編集')}} -
+ + + {{-- ★ チェック + 編集 用の1列 --}} + - {{-- ▼ データ本体(既存表示そのまま) --}} - - - - - - - - - - - @endforeach - -
+ + {{ mb_substr($item->price_parkplaceid, 0, 10) }}{{ mb_substr($item->park_id, 0, 10) }}{{ mb_substr($item->prine_name, 0, 10) }}{{ mb_substr($item->price_month, 0, 10) }}{{ mb_substr($item->user_categoryid, 0, 10) }}{{ mb_substr($item->price, 0, 10) }}{{ mb_substr($item->psection_id, 0, 10) }}{{ mb_substr($item->price_ptypeid, 0, 10) }}{{ mb_substr($item->pplace_id, 0, 10) }}
-
+ {{-- ▼ ソート対象列 --}} + + 駐輪場所ID + + + 駐輪場ID + - {{-- ▼ ページネーション(下部・右寄せ:必要に応じて表示) --}} -
- {{ $list->appends(['sort' => $sort, 'sort_type' => $sort_type])->links('pagination') }} + {{-- ▼ ソート不要 --}} + 商品名 + 期間 + 利用者分類ID + 駐輪料金(税込) + + {{-- ▼ ソート対象列 --}} + + 車種区分ID + + + 駐輪分類 + + + 駐車車室ID + + + + + + @foreach($list as $item) + + {{-- ★ 同じセル内に チェック + 編集ボタン --}} + +
+ + 編集 +
+ + + {{-- データ列 --}} + {{ $item->price_parkplaceid }} + {{ $item->park_id }} + {{ $item->prine_name }} + {{ $item->price_month }} + {{ $item->user_categoryid }} + {{ $item->price }} + {{ $item->psection_id }} + {{ $item->price_ptypeid }} + {{ $item->pplace_id }} + + @endforeach + + + +
+ + +
@@ -133,3 +156,23 @@ document.getElementById('checkbox_all')?.addEventListener('change', function(e){ }); @endsection + +@section('scripts') + +@endsection \ No newline at end of file diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index d2fb791..5b9ccd7 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -35,6 +35,8 @@ + +