From 63cbd8a05deeaf256e4d82f487d9efa5829846b0 Mon Sep 17 00:00:00 2001 From: "kin.rinzen" Date: Tue, 16 Sep 2025 17:43:14 +0900 Subject: [PATCH] =?UTF-8?q?=E9=A7=90=E8=BC=AA=E5=88=86=E9=A1=9E=E3=83=9E?= =?UTF-8?q?=E3=82=B9=E3=82=BF=E7=94=BB=E9=9D=A2=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/PsectionController.php | 35 ++- .../Controllers/Admin/PtypeController.php | 47 ++-- app/Models/Ptype.php | 3 +- .../views/admin/psection/_form.blade.php | 205 ++++-------------- resources/views/admin/psection/add.blade.php | 81 ++++--- resources/views/admin/psection/edit.blade.php | 43 +--- resources/views/admin/psection/list.blade.php | 22 +- resources/views/admin/ptypes/_form.blade.php | 22 +- resources/views/admin/ptypes/add.blade.php | 10 +- resources/views/admin/ptypes/edit.blade.php | 7 +- resources/views/admin/ptypes/list.blade.php | 130 ++++++----- resources/views/layouts/app.blade.php | 2 +- routes/web.php | 20 +- 13 files changed, 264 insertions(+), 363 deletions(-) diff --git a/app/Http/Controllers/Admin/PsectionController.php b/app/Http/Controllers/Admin/PsectionController.php index 66c287e..441afaa 100644 --- a/app/Http/Controllers/Admin/PsectionController.php +++ b/app/Http/Controllers/Admin/PsectionController.php @@ -37,21 +37,23 @@ class PsectionController extends Controller 'sort_type' => $sortType, ]); } - - - + // 新規追加 public function add(Request $request) { if ($request->isMethod('post')) { $validated = $request->validate([ - 'psection_id' => 'required|integer|unique:psection,psection_id', + // 'psection_id' は自動採番なので不要 'psection_subject' => 'required|string|max:255', ]); + Psection::create($validated); - return redirect()->route('psection')->with('success', '車種区分を追加しました'); + + return redirect()->route('psections')->with('success', '車室区分を追加しました'); } - return view('admin.psection.add'); + + // GET の場合は空のモデルを渡してフォームを表示 + return view('admin.psection.add', ['psection' => new Psection()]); } // 編集 @@ -70,7 +72,7 @@ class PsectionController extends Controller $psection->update($validated); // 成功メッセージ & リダイレクト - return redirect()->route('psection')->with('success', '車種区分を更新しました'); + return redirect()->route('psections')->with('success', '車種区分を更新しました'); } // 編集画面を表示 @@ -88,11 +90,20 @@ class PsectionController extends Controller // 削除 public function delete(Request $request) { - $ids = $request->input('pk', []); - if (!empty($ids)) { - Psection::whereIn('psection_id', $ids)->delete(); - return redirect()->route('psection')->with('success', '削除しました'); + $arr_pk = $request->get('pk'); + + if (!is_array($arr_pk)) { + $arr_pk = [$arr_pk]; } - return redirect()->route('psection')->with('error', '削除対象を選択してください'); + + if ($arr_pk && count($arr_pk) > 0) { + if (Psection::whereIn('psection_id', $arr_pk)->delete()) { + return redirect()->route('psections')->with('success', __("削除が完了しました。")); + } else { + return redirect()->route('psections')->with('error', __('削除に失敗しました。')); + } + } + return redirect()->route('psections')->with('error', __('削除するデータを選択してください。')); } + } diff --git a/app/Http/Controllers/Admin/PtypeController.php b/app/Http/Controllers/Admin/PtypeController.php index 39d88c3..3cd0e02 100644 --- a/app/Http/Controllers/Admin/PtypeController.php +++ b/app/Http/Controllers/Admin/PtypeController.php @@ -24,9 +24,11 @@ class PtypeController extends Controller ]; $inputs['isMethodPost'] = $request->isMethod('post'); $inputs['list'] = Ptype::search($inputs); + if ($inputs['list']->total() > 0 && $inputs['page'] > $inputs['list']->lastPage()) { return redirect()->route('ptypes'); } + return view('admin.ptypes.list', $inputs); } @@ -41,7 +43,7 @@ class PtypeController extends Controller if ($request->isMethod('POST')) { $rules = [ 'ptype_subject' => 'required|string|max:255', - 'ptype_sort' => 'nullable|integer', + 'floor_sort' => 'nullable|integer', 'ptype_remarks' => 'nullable|string|max:255', ]; $messages = [ @@ -75,28 +77,30 @@ class PtypeController extends Controller { $ptype = Ptype::getByPk($pk); if (empty($pk) || empty($ptype)) { - abort('404'); + abort(404); } - $data = $ptype->getAttributes(); + + // 追加のドロップダウンなどがある場合 $dataList = $this->getDataDropList(); - $data = array_merge($data, $dataList); + if ($request->isMethod('POST')) { $type = false; - // ここを修正 + + // バリデーションルール $rules = [ 'ptype_subject' => 'required|string|max:255', - 'ptype_sort' => 'nullable|integer', + 'floor_sort' => 'nullable|integer', 'ptype_remarks' => 'nullable|string|max:255', ]; $messages = [ 'ptype_subject.required' => '駐輪分類名は必須です。', ]; + $validator = Validator::make($request->all(), $rules, $messages); - $requestAll = $request->all(); - $data = array_merge($data, $requestAll); + if (!$validator->fails()) { - \DB::transaction(function () use ($data, &$type, $ptype) { - $ptype->fill($data); + \DB::transaction(function () use ($request, &$type, $ptype) { + $ptype->fill($request->all()); $ptype->save(); $type = true; }); @@ -107,20 +111,33 @@ class PtypeController extends Controller $request->session()->flash('error', __('更新に失敗しました')); } } else { - $data['errorMsg'] = $this->__buildErrorMessasges($validator); + return redirect()->back() + ->withErrors($validator) + ->withInput(); } } + + // Blade に渡すときはモデルそのものを渡す if ($view != '') { - return view($view, $data); + return view($view, array_merge($dataList, ['item' => $ptype])); } - return view('admin.ptypes.edit', $data); + return view('admin.ptypes.edit', array_merge($dataList, [ + 'item' => $ptype, + 'ptype_id' => $ptype->ptype_id, + ])); } public function delete(Request $request) { $arr_pk = $request->get('pk'); - if ($arr_pk) { - if (Ptype::deleteByPk($arr_pk)) { + + // 単体削除の場合 string が来るので配列に変換 + if (!is_array($arr_pk)) { + $arr_pk = [$arr_pk]; + } + + if ($arr_pk && count($arr_pk) > 0) { + if (Ptype::whereIn('ptype_id', $arr_pk)->delete()) { return redirect()->route('ptypes')->with('success', __("削除が完了しました。")); } else { return redirect()->route('ptypes')->with('error', __('削除に失敗しました。')); diff --git a/app/Models/Ptype.php b/app/Models/Ptype.php index aeb6fe6..78c7853 100644 --- a/app/Models/Ptype.php +++ b/app/Models/Ptype.php @@ -33,6 +33,7 @@ class Ptype extends Model 'ptype_subject', 'ptype_remarks', 'operator_id', + 'floor_sort', ]; public static function search($inputs) @@ -47,7 +48,7 @@ class Ptype extends Model if (!empty($inputs['isExport'])) { return $list->get(); } else { - return $list->paginate(\App\Models\Utils::item_per_page); + return $list->paginate(20); } } diff --git a/resources/views/admin/psection/_form.blade.php b/resources/views/admin/psection/_form.blade.php index 1bb85db..c88b21c 100644 --- a/resources/views/admin/psection/_form.blade.php +++ b/resources/views/admin/psection/_form.blade.php @@ -1,172 +1,63 @@ -{{-- 駐輪場マスタ 共通フォーム --}} +@if(Session::has('success')) + +@elseif(Session::has('error')) +
+ +

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

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

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

+ {!! $errorMsg !!} +
+@endif -
- @csrf - - {{-- 駐輪場ID --}} +
+ {{-- 車室区分ID --}}
- -
- + +
+
- {{-- 市区 --}} + {{-- 車室区分名 --}}
- -
- + +
+
- {{-- 駐輪場名 --}} + {{-- ▼ 下部ボタン --}}
- -
- -
-
+
+ {{-- 登録ボタン --}} + - {{-- 駐輪場ふりがな --}} -
- -
- -
-
- - {{-- 駐輪場五十音 --}} -
- -
- -
-
- - {{-- 住所 --}} -
- -
- -
-
- - {{-- 閉設フラグ --}} -
- -
-
- - -
-
- - -
-
- - -
-
-
- - {{-- 閉設日 --}} -
- -
- -
-
- - {{-- 残警告チェックフラグ --}} -
- -
- -
-
- - {{-- 印字数 --}} -
- -
- -
-
- - {{-- 最新キープアライブ --}} -
- -
- -
-
- - {{-- ---- 以下为未来扩展的字段,请用时补充数据库和控制器变量,并去掉注释 ---- --}} - - {{-- -
- -
- -
-
- -
- -
- -
- -
- -
-
- -
- -
-
- - -
-
- - -
-
-
- --}} - - {{-- 備考 --}} -
- -
- -
-
- - {{-- ここから他のフィールドも同様に追加 --}} - {{-- ... --}} - - {{-- 图片上传字段样例 --}} - {{-- -
- -
- - @if(!empty($parking_image1_url)) - 駐輪場画像1 + {{-- 削除ボタン(編集画面のみ表示) --}} + @if(!empty($psection->psection_id)) + +
+ @csrf + + +
@endif
- --}} - +
\ No newline at end of file diff --git a/resources/views/admin/psection/add.blade.php b/resources/views/admin/psection/add.blade.php index 94a957b..01df0df 100644 --- a/resources/views/admin/psection/add.blade.php +++ b/resources/views/admin/psection/add.blade.php @@ -1,47 +1,46 @@ + @extends('layouts.app') -@section('title', '車種区分新規登録') +@section('title', '[東京都|〇〇駐輪場] 車種区分マスタ') + @section('content') -
-
-
-

新規登録

-
- + +
+
+
+
+

新規登録

+
+
+ +
+
+
+
+ + + +
+
+ + +
+
+
+
+ + + + @include('admin.psection._form',['isEdit'=>0,'isInfo'=>0]) +
+
+
-
-
-
-
+
+ - @if ($errors->any()) -
-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif - -
- @csrf -
- - -
-
- - -
- - -
-
- @endsection diff --git a/resources/views/admin/psection/edit.blade.php b/resources/views/admin/psection/edit.blade.php index 7acbf56..6545c1d 100644 --- a/resources/views/admin/psection/edit.blade.php +++ b/resources/views/admin/psection/edit.blade.php @@ -7,12 +7,12 @@
-

車種区分マスタ 編集

+

編集

@@ -23,44 +23,9 @@
-
+ @csrf -
- {{-- 車種区分ID(読み取り専用) --}} -
- -
- -
-
- - {{-- 車種区分名 --}} -
- -
- - @error('psection_subject') -
{{ $message }}
- @enderror -
-
-
- - {{-- ▼ 下部ボタン --}} -
- {{-- 登録ボタン --}} - - - {{-- 削除ボタン(同じ行に並べる) --}} - - @csrf - @method('DELETE') - - -
+ @include('admin.psection._form',['isEdit'=>1,'isInfo'=>0])
diff --git a/resources/views/admin/psection/list.blade.php b/resources/views/admin/psection/list.blade.php index 3a44251..8b4a24b 100644 --- a/resources/views/admin/psection/list.blade.php +++ b/resources/views/admin/psection/list.blade.php @@ -20,12 +20,13 @@
+{{-- ▼ メインコンテンツ --}}
{{-- ▼ アクションボタン --}}
- 新規 + 新規
@@ -38,8 +39,23 @@ ])->links('pagination') }}
+ {{-- ▼ フラッシュメッセージ --}} + @if(Session::has('success')) + + @endif + + @if(Session::has('error')) + + @endif + @if ($list->count() > 0) -
+ @csrf
@@ -70,7 +86,7 @@ {{-- ▼ 統合セル:チェック + 編集 --}} - 編集 diff --git a/resources/views/admin/ptypes/_form.blade.php b/resources/views/admin/ptypes/_form.blade.php index d45648e..5ec2822 100644 --- a/resources/views/admin/ptypes/_form.blade.php +++ b/resources/views/admin/ptypes/_form.blade.php @@ -16,9 +16,6 @@ {!! $errorMsg !!}
@endif -
- -
@@ -36,7 +33,7 @@
- +
@@ -47,6 +44,19 @@
-
- +{{-- ▼ 下部ボタン --}} +
+ {{-- 登録ボタン --}} + + + {{-- 削除ボタン(編集画面のみ表示) --}} + @if(!empty($ptype_id)) + +
+ @csrf + + +
+ @endif
diff --git a/resources/views/admin/ptypes/add.blade.php b/resources/views/admin/ptypes/add.blade.php index ba80cfe..e542e26 100644 --- a/resources/views/admin/ptypes/add.blade.php +++ b/resources/views/admin/ptypes/add.blade.php @@ -8,14 +8,14 @@
-

駐輪分類マスタ

+

新規登録

@@ -31,7 +31,7 @@
-
+ diff --git a/resources/views/admin/ptypes/edit.blade.php b/resources/views/admin/ptypes/edit.blade.php index c7ec050..06ef475 100644 --- a/resources/views/admin/ptypes/edit.blade.php +++ b/resources/views/admin/ptypes/edit.blade.php @@ -7,12 +7,11 @@
-

[東京都|〇〇駐輪場] 駐輪分類マスタ

+

編集

@@ -30,7 +29,7 @@
- + @csrf @include('admin.ptypes._form',['isEdit'=>1,'isInfo'=>0]) diff --git a/resources/views/admin/ptypes/list.blade.php b/resources/views/admin/ptypes/list.blade.php index 28ecb8f..c6d2177 100644 --- a/resources/views/admin/ptypes/list.blade.php +++ b/resources/views/admin/ptypes/list.blade.php @@ -11,8 +11,8 @@
@@ -22,11 +22,17 @@ {{-- ▼ メインコンテンツ --}}
+ {{-- ▼ ソート用 hidden フォーム --}} +
+ @csrf + + +
{{-- ▼ アクションボタン(市区マスタ準拠) --}}
- 新規 -
@@ -51,94 +57,80 @@ @endif {{-- ▼ 一覧(編集+チェックを統合列に変更:背景 #faebd7) --}} -
+ @csrf
- + {{-- ▼ ページネーション(表の上に表示) --}} +
+ {{ $list->appends([ + 'sort' => $sort ?? '', + 'sort_type' => $sort_type ?? '' + ])->links('pagination') }} +
+ +
- {{-- ▼ 統合列:全選択 + 編集(市区マスタ準拠) --}} - - {{-- ▼ ソート可能ヘッダー(ID / 名称 / 階数ソート順 / 備考) --}} - - - - + {{-- ▼ ソート不可列 --}} + + + - + @foreach($list as $item) {{-- ▼ 統合セル:チェック + 編集 --}} - {{-- ▼ データ列 --}} - + @endforeach
+ {{-- ★ チェック + 編集 用の1列 --}} + - - - 駐輪分類ID - @if($sort == 'ptype_id') - @if($sort_type == 'asc') - - @else - - @endif - @endif - + - - 駐輪分類名 - @if($sort == 'ptype_subject') - @if($sort_type == 'asc') - - @else - - @endif - @endif - - - - 階数ソート順 - @if($sort == 'ptype_sort') - @if($sort_type == 'asc') - - @else - - @endif - @endif - - - - 備考 - @if($sort == 'ptype_remarks') - @if($sort_type == 'asc') - - @else - - @endif - @endif - + {{-- ▼ ソート対象列 --}} + + 駐輪分類ID 駐輪分類名階数ソート順備考
- - 編集 + +
+ + 編集 +
{{ $item->ptype_id }} {{ $item->ptype_subject }}{{ $item->ptype_sort }}{{ $item->floor_sort }} {{ $item->ptype_remarks }}
- {{-- ▼ ページネーションをテーブルの外、左下に表示(Bootstrap4スタイル&パラメータ維持) --}} -
- {{ $list->appends(request()->except('page'))->links('pagination::bootstrap-4') }} +
@endsection + +@section('scripts') + +@endsection + diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 3338b7b..6388f52 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -457,7 +457,7 @@

{{ __("駐輪場所、料金マスタ") }}

- diff --git a/routes/web.php b/routes/web.php index 5537399..79ca525 100644 --- a/routes/web.php +++ b/routes/web.php @@ -187,19 +187,19 @@ Route::middleware('auth')->group(function () { Route::post('/admin/prices/export', [PriceController::class, 'export'])->name('prices_export'); //車種区分マスタ - Route::match(['get', 'post'], '/admin/psection', [PsectionController::class, 'list'])->name('psection'); - Route::match(['get', 'post'], '/admin/psection/add', [PsectionController::class, 'add'])->name('psection_add'); - Route::match(['get', 'post'], '/admin/psection/edit/{id}', [PsectionController::class, 'edit'])->name('psection_edit')->where(['id' => '[0-9]+']); - Route::post('/admin/psection/delete', [PsectionController::class, 'delete'])->name('psection_delete'); + Route::match(['get', 'post'], '/admin/psection', [PsectionController::class, 'list'])->name('psections'); + Route::match(['get', 'post'], '/admin/psection/add', [PsectionController::class, 'add'])->name('psections_add'); + Route::match(['get', 'post'], '/admin/psection/edit/{id}', [PsectionController::class, 'edit'])->name('psections_edit')->where(['id' => '[0-9]+']); + Route::post('/admin/psection/delete', [PsectionController::class, 'delete'])->name('psections_delete'); //駐輪分類マスタ Route::match(['get', 'post'], '/admin/ptypes', [PtypeController::class, 'list'])->name(name: 'ptypes'); - Route::match(['get', 'post'], '/admin/ptypes/add', [PtypeController::class, 'add'])->name('ptype_add'); - Route::match(['get', 'post'], '/admin/ptypes/edit/{id}', [PtypeController::class, 'edit'])->name('ptype_edit')->where(['id' => '[0-9]+']); - Route::match(['get', 'post'], '/admin/ptypes/info/{id}', [PtypeController::class, 'info'])->name('ptype_info')->where(['id' => '[0-9]+']); - Route::match(['get', 'post'], '/admin/ptypes/delete', [PtypeController::class, 'delete'])->name('ptype_delete'); - Route::match(['get', 'post'], '/admin/ptypes/import', [PtypeController::class, 'import'])->name('ptype_import'); - Route::get('/admin/ptypes/export', [PtypeController::class, 'export'])->name('ptype_export'); + Route::match(['get', 'post'], '/admin/ptypes/add', [PtypeController::class, 'add'])->name('ptypes_add'); + Route::match(['get', 'post'], '/admin/ptypes/edit/{id}', [PtypeController::class, 'edit'])->name('ptypes_edit')->where(['id' => '[0-9]+']); + Route::match(['get', 'post'], '/admin/ptypes/info/{id}', [PtypeController::class, 'info'])->name('ptypes_info')->where(['id' => '[0-9]+']); + Route::match(['get', 'post'], '/admin/ptypes/delete', [PtypeController::class, 'delete'])->name('ptypes_delete'); + Route::match(['get', 'post'], '/admin/ptypes/import', [PtypeController::class, 'import'])->name('ptypes_import'); + Route::get('/admin/ptypes/export', [PtypeController::class, 'export'])->name('ptypes_export'); //定期利用・契約状況 Route::match(['get', 'post'], '/periodical', [PeriodicalController::class, 'list'])->name('periodical');