From b0ed603472a7b4c652f2a82ff07cbdab981fcca8 Mon Sep 17 00:00:00 2001 From: "kin.rinzen" Date: Fri, 19 Sep 2025 15:21:07 +0900 Subject: [PATCH] =?UTF-8?q?=E8=BF=91=E5=82=8D=E9=A7=85=E3=83=9E=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E7=94=BB=E9=9D=A2=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/StationController.php | 25 +- .../views/admin/stations/_form.blade.php | 216 +++++++++--------- resources/views/admin/stations/add.blade.php | 6 +- resources/views/admin/stations/edit.blade.php | 6 +- resources/views/admin/stations/list.blade.php | 38 +-- 5 files changed, 148 insertions(+), 143 deletions(-) diff --git a/app/Http/Controllers/Admin/StationController.php b/app/Http/Controllers/Admin/StationController.php index beeb510..6943f88 100644 --- a/app/Http/Controllers/Admin/StationController.php +++ b/app/Http/Controllers/Admin/StationController.php @@ -16,7 +16,6 @@ class StationController extends Controller $sort = $request->input('sort', 'station_id'); $sort_type = $request->input('sort_type', 'asc'); - // 許可されたソート項目のみ $allowedSorts = [ 'station_id', 'park_id', @@ -32,19 +31,23 @@ class StationController extends Controller $sort_type = 'asc'; } - // 必要カラムのみ取得 - $stations = Station::select([ - 'station_id', - 'station_neighbor_station', - 'station_name_ruby', - 'station_route_name', - 'park_id', - 'operator_id' - ])->orderBy($sort, $sort_type)->paginate(20); + $list = Station::select([ + 'station_id', + 'station_neighbor_station', + 'station_name_ruby', + 'station_route_name', + 'park_id', + 'operator_id', + 'station_latitude', + 'station_longitude', + ]) + ->orderBy($sort, $sort_type) + ->paginate(20); - return view('admin.stations.list', compact('stations', 'sort', 'sort_type')); + return view('admin.stations.list', compact('list', 'sort', 'sort_type')); } + /** * 新規登録 */ diff --git a/resources/views/admin/stations/_form.blade.php b/resources/views/admin/stations/_form.blade.php index 8f752b5..47010ed 100644 --- a/resources/views/admin/stations/_form.blade.php +++ b/resources/views/admin/stations/_form.blade.php @@ -11,140 +11,144 @@ @endif -@php - // $isEdit = 1 or 0 -@endphp -
- - {{-- 近傍駅ID(自動採番) --}} - - - - + + - {{-- 駐輪場ID --}} - - - - + + - {{-- 近傍駅 --}} - - - - + maxlength="50" required> + + @error('station_neighbor_station') +
{{ $message }}
+ @enderror + - {{-- 近傍駅ふりがな --}} - - - - + maxlength="50" required> + + @error('station_name_ruby') +
{{ $message }}
+ @enderror + - {{-- 路線名 --}} - - - - + maxlength="50" required> + + @error('station_route_name') +
{{ $message }}
+ @enderror + - {{-- 緯度 --}} - - - - + step="any" maxlength="20" required> + + @error('latitude') +
{{ $message }}
+ @enderror + - {{-- 経度 --}} - - - - -
{{ __('近傍駅ID') }} + {{-- バリデーションエラー表示 --}} + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + +
+ + +
+ +
+
+
-
{{ __('駐車場ID') }} + +
+ +
+
+
-
{{ __('近傍駅') }} + +
+ +
+
+
- @error('station_neighbor_station') -
{{ $message }}
- @enderror -
{{ __('近傍駅ふりがな') }} + +
+ +
+
+
- @error('station_name_ruby') -
{{ $message }}
- @enderror -
{{ __('路線名') }} + +
+ +
+
+
- @error('station_route_name') -
{{ $message }}
- @enderror -
{{ __('近傍駅座標(緯度)') }} + +
+ +
+
+
- @error('latitude') -
{{ $message }}
- @enderror -
{{ __('近傍駅座標(経度)') }} + +
+ +
+
+
- @error('longitude') -
{{ $message }}
- @enderror -
+ step="any" maxlength="20" required> +
+ @error('longitude') +
{{ $message }}
+ @enderror + - {{-- 登録・削除 ボタン --}} -
- @if($isInfo) - {{-- 詳細画面:編集に遷移 --}} +
- - 編集 - - @else - {{-- 新規/編集 共通フォーム --}} - + {{-- ▼ 下部ボタン --}} +
+ {{-- 登録ボタン --}} + - {{-- 編集時のみ削除可能 --}} - @if($isEdit && isset($station->id)) -
- @csrf - - -
- @endif + {{-- 削除ボタン(編集画面のみ表示) --}} + @if(!empty($station->station_id)) + +
+ @csrf + + +
@endif
- -@section('scripts') - -@endsection + + diff --git a/resources/views/admin/stations/add.blade.php b/resources/views/admin/stations/add.blade.php index 68b68f5..623db07 100644 --- a/resources/views/admin/stations/add.blade.php +++ b/resources/views/admin/stations/add.blade.php @@ -24,11 +24,7 @@
@csrf - @include('admin.stations._form', [ - 'isEdit' => 0, - 'isInfo' => 0, - 'station' => $station ?? null - ]) + @include('admin.stations._form', ['isEdit' => false])
diff --git a/resources/views/admin/stations/edit.blade.php b/resources/views/admin/stations/edit.blade.php index 44622ab..67331b4 100644 --- a/resources/views/admin/stations/edit.blade.php +++ b/resources/views/admin/stations/edit.blade.php @@ -26,11 +26,7 @@
@csrf - @include('admin.stations._form', [ - 'isEdit' => 1, - 'isInfo' => 0, - 'station' => $station - ]) + @include('admin.stations._form', ['isEdit' => true])
diff --git a/resources/views/admin/stations/list.blade.php b/resources/views/admin/stations/list.blade.php index b96a32d..77c0fe6 100644 --- a/resources/views/admin/stations/list.blade.php +++ b/resources/views/admin/stations/list.blade.php @@ -23,6 +23,7 @@
+ {{-- 並び替え用 hidden --}}
@csrf @@ -30,15 +31,27 @@
-
+ {{-- ▼ ボタンエリア --}} +
- + {{-- 削除 --}} + -
- {{ $stations->appends(['sort' => $sort ?? '', 'sort_type' => $sort_type ?? ''])->links('pagination') }} +
+ + {{-- ▼ ページネーション --}} +
+
+ {{ $list->appends([ + 'sort' => $sort ?? '', + 'sort_type' => $sort_type ?? '' + ])->links('pagination') }}
+ {{-- ▼ テーブル --}}
@if(Session::has('success')) @endif - - -
- @if(session('success')) -
{{ session('success') }}
- @elseif(session('error')) -
{{ session('error') }}
- @endif -
+
@@ -80,12 +85,13 @@ 近傍駅 近傍駅ふりがな 路線名 - 近傍駅座標(緯度) - 近傍駅座標(経度) + {{ __('近傍駅座標(緯度)') }} + {{ __('近傍駅座標(経度)') }} + - @foreach($stations as $station) + @foreach($list as $station) {{-- ★ 同じセル内に チェック + 編集ボタン) --}}