diff --git a/app/Http/Controllers/Admin/PtypeController.php b/app/Http/Controllers/Admin/PtypeController.php
index 3cd0e02..23569e4 100644
--- a/app/Http/Controllers/Admin/PtypeController.php
+++ b/app/Http/Controllers/Admin/PtypeController.php
@@ -31,125 +31,112 @@ class PtypeController extends Controller
return view('admin.ptypes.list', $inputs);
}
-
+
+ /**
+ * 新規登録(画面/処理)
+ */
public function add(Request $request)
{
- $inputs = [
- //TODO 駐輪分類ID not found in database specs
- 'ptype_subject' => $request->input('ptype_subject'), // 駐輪分類名
- 'ptype_remarks' => $request->input('ptype_remarks'), // 備考
- ];
-
- if ($request->isMethod('POST')) {
- $rules = [
- 'ptype_subject' => 'required|string|max:255',
- 'floor_sort' => 'nullable|integer',
- 'ptype_remarks' => 'nullable|string|max:255',
- ];
- $messages = [
- 'ptype_subject.required' => '駐輪分類名は必須です。',
- ];
- $validator = Validator::make($request->all(), $rules, $messages);
- if (!$validator->fails()) {
- \DB::transaction(function () use ($inputs, &$type) {
- $new = new Ptype();
- $new->fill($inputs);
- if ($new->save()) {
- $type = true;
- }
-
- });
- if ($type) {
- $request->session()->flash('success', __('データ新規作成しました。'));
- return redirect()->route('ptypes');
- } else {
- $request->session()->flash('error', __('新規作成に失敗しました'));
- }
- } else {
- $inputs['errorMsg'] = $this->__buildErrorMessasges($validator);
- }
+ if ($request->isMethod('get')) {
+ // 新規時は空のレコードを用意してフォーム描画
+ return view('admin.ptypes.add', [
+ 'isEdit' => false,
+ 'record' => new Ptype(), // ← ★ Blade側で record->〇〇 が使える
+ ]);
}
- return view('admin.ptypes.add', $inputs);
+ // POST時:バリデーション
+ $rules = [
+ 'ptype_subject' => 'required|string|max:255',
+ 'ptype_remarks' => 'nullable|string|max:255',
+ ];
+ $messages = [
+ 'ptype_subject.required' => '駐輪分類名は必須です。',
+ ];
+
+ $validator = Validator::make($request->all(), $rules, $messages);
+
+ if ($validator->fails()) {
+ return redirect()->back()->withErrors($validator)->withInput();
+ }
+
+ DB::transaction(function () use ($request) {
+ $new = new Ptype();
+ $new->fill($request->only(['ptype_subject', 'ptype_remarks']));
+ $new->save();
+ });
+
+ return redirect()->route('ptypes')->with('success', '登録しました。');
}
- public function edit(Request $request, $pk, $view = '')
+ /**
+ * 編集(画面/処理)
+ */
+ public function edit(Request $request, $id)
{
- $ptype = Ptype::getByPk($pk);
- if (empty($pk) || empty($ptype)) {
+ // 該当データ取得
+ $record = Ptype::find($id);
+ if (!$record) {
abort(404);
}
- // 追加のドロップダウンなどがある場合
- $dataList = $this->getDataDropList();
-
- if ($request->isMethod('POST')) {
- $type = false;
-
- // バリデーションルール
- $rules = [
- 'ptype_subject' => 'required|string|max:255',
- 'floor_sort' => 'nullable|integer',
- 'ptype_remarks' => 'nullable|string|max:255',
- ];
- $messages = [
- 'ptype_subject.required' => '駐輪分類名は必須です。',
- ];
-
- $validator = Validator::make($request->all(), $rules, $messages);
-
- if (!$validator->fails()) {
- \DB::transaction(function () use ($request, &$type, $ptype) {
- $ptype->fill($request->all());
- $ptype->save();
- $type = true;
- });
- if ($type) {
- $request->session()->flash('success', __('更新に成功しました'));
- return redirect()->route('ptypes');
- } else {
- $request->session()->flash('error', __('更新に失敗しました'));
- }
- } else {
- return redirect()->back()
- ->withErrors($validator)
- ->withInput();
- }
+ if ($request->isMethod('get')) {
+ // 編集画面表示
+ return view('admin.ptypes.edit', [
+ 'isEdit' => true,
+ 'record' => $record,
+ ]);
}
- // Blade に渡すときはモデルそのものを渡す
- if ($view != '') {
- return view($view, array_merge($dataList, ['item' => $ptype]));
+ // POST時:バリデーション
+ $rules = [
+ 'ptype_subject' => 'required|string|max:255',
+ 'floor_sort' => 'nullable|string|max:50',
+
+ 'ptype_remarks' => 'nullable|string|max:255',
+ ];
+ $messages = [
+ 'ptype_subject.required' => '駐輪分類名は必須です。',
+ ];
+
+ $validator = Validator::make($request->all(), $rules, $messages);
+
+ if ($validator->fails()) {
+ return redirect()->back()->withErrors($validator)->withInput();
}
- return view('admin.ptypes.edit', array_merge($dataList, [
- 'item' => $ptype,
- 'ptype_id' => $ptype->ptype_id,
- ]));
+
+ DB::transaction(function () use ($request, $record) {
+ $record->fill($request->only(['ptype_subject','floor_sort', 'ptype_remarks']));
+ $record->save();
+ });
+
+ return redirect()->route('ptypes')->with('success', '更新しました。');
}
+ /**
+ * 削除(単一/複数対応)
+ */
public function delete(Request $request)
{
- $arr_pk = $request->get('pk');
+ $ids = [];
- // 単体削除の場合 string が来るので配列に変換
- if (!is_array($arr_pk)) {
- $arr_pk = [$arr_pk];
+ if ($request->filled('id')) {
+ $ids[] = (int) $request->input('id');
}
- 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', __('削除に失敗しました。'));
- }
+ if (is_array($request->input('pk'))) {
+ $ids = array_merge($ids, $request->input('pk'));
}
- return redirect()->route('ptypes')->with('error', __('削除するデータを選択してください。'));
- }
+ $ids = array_values(array_unique(array_map('intval', $ids)));
- public function info(Request $request, $id)
- {
- return $this->edit($request, $id, 'admin.ptypes.info');
+ if (empty($ids)) {
+ return back()->with('error', '削除対象が選択されていません。');
+ }
+
+ Ptype::whereIn('ptype_id', $ids)->delete();
+
+ return redirect()->route('ptypes')->with('success', '削除しました。');
}
public function getDataDropList()
diff --git a/app/Http/Controllers/Admin/StationController.php b/app/Http/Controllers/Admin/StationController.php
index 74901c9..0866281 100644
--- a/app/Http/Controllers/Admin/StationController.php
+++ b/app/Http/Controllers/Admin/StationController.php
@@ -5,6 +5,10 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Station;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Facades\DB;
+use App\Models\Park;
+
class StationController extends Controller
{
@@ -38,8 +42,8 @@ class StationController extends Controller
'station_route_name',
'park_id',
'operator_id',
- // 'station_latitude', 追加予定
- // 'station_longitude', 追加予定
+ 'station_latitude',
+ 'station_longitude',
])
->orderBy($sort, $sort_type)
->paginate(20);
@@ -48,74 +52,140 @@ class StationController extends Controller
}
- /**
- * 新規登録
- */
public function add(Request $request)
{
- if ($request->isMethod('post')) {
- $validated = $request->validate([
- 'station_neighbor_station' => 'required|string|max:255',
- 'station_name_ruby' => 'nullable|string|max:255',
- 'station_route_name' => 'nullable|string|max:255',
- 'park_id' => 'nullable|integer',
- 'operator_id' => 'nullable|integer',
- ]);
+ if ($request->isMethod('get')) {
+ // 駐車場リストを取得(プルダウン用)
+ $parks = Park::orderBy('park_name')->pluck('park_name', 'park_id');
- Station::create($validated);
- return redirect()->route('stations')->with('success', '近傍駅が登録されました');
+ // 新規時:空レコードを渡す
+ return view('admin.stations.add', [
+ 'isEdit' => false,
+ 'record' => new Station(),
+ 'parks' => $parks, // ← これを追加
+ ]);
}
- return view('admin.stations.add');
+ // POST時:バリデーション
+ $rules = [
+ 'station_neighbor_station' => 'required|string|max:255',
+ 'station_name_ruby' => 'required|string|max:255',
+ 'station_route_name' => 'required|string|max:255',
+ 'station_latitude' => 'required|numeric',
+ 'station_longitude' => 'required|numeric',
+ 'operator_id' => 'nullable|integer',
+ 'park_id' => 'required|integer',
+ ];
+
+ $messages = [
+ 'station_latitude.required' => '緯度は必須項目です。',
+ 'station_longitude.required' => '経度は必須項目です。',
+ ];
+
+ $validator = Validator::make($request->all(), $rules, $messages);
+
+ if ($validator->fails()) {
+ return redirect()->back()->withErrors($validator)->withInput();
+ }
+
+ DB::transaction(function () use ($request) {
+ Station::create($request->only([
+ 'station_neighbor_station',
+ 'station_name_ruby',
+ 'station_route_name',
+ 'station_latitude',
+ 'station_longitude',
+ 'park_id',
+ 'operator_id',
+ ]));
+ });
+
+ return redirect()->route('stations')->with('success', '登録しました。');
}
/**
- * 編集
+ * 編集(画面/処理)
*/
public function edit(Request $request, $id)
{
- $station = Station::findOrFail($id);
+ $record = Station::findOrFail($id);
- if ($request->isMethod('post')) {
- $validated = $request->validate([
- 'station_neighbor_station' => 'required|string|max:255',
- 'station_name_ruby' => 'nullable|string|max:255',
- 'station_route_name' => 'nullable|string|max:255',
- 'park_id' => 'nullable|integer',
- 'operator_id' => 'nullable|integer',
+ if ($request->isMethod('get')) {
+ // 駐車場リストを取得(プルダウン用)
+ $parks = Park::orderBy('park_name')->pluck('park_name', 'park_id');
+
+ return view('admin.stations.edit', [
+ 'isEdit' => true,
+ 'record' => $record,
+ 'parks' => $parks, // ← ここを追加
]);
-
- $station->update($validated);
- return redirect()->route('stations')->with('success', '更新しました');
}
- return view('admin.stations.edit', compact('station'));
+ // ▼ POST時:バリデーション
+ $rules = [
+ 'station_neighbor_station' => 'required|string|max:255',
+ 'station_name_ruby' => 'required|string|max:255',
+ 'station_route_name' => 'required|string|max:255',
+ 'station_latitude' => 'required|numeric',
+ 'station_longitude' => 'required|numeric',
+ 'operator_id' => 'nullable|integer',
+ 'park_id' => 'required|integer',
+ ];
+
+ $messages = [
+ 'station_latitude.required' => '緯度は必須項目です。',
+ 'station_longitude.required' => '経度は必須項目です。',
+ ];
+
+ $validator = Validator::make($request->all(), $rules, $messages);
+
+ if ($validator->fails()) {
+ return redirect()->back()->withErrors($validator)->withInput();
+ }
+
+ DB::transaction(function () use ($request, $record) {
+ $record->update($request->only([
+ 'station_neighbor_station',
+ 'station_name_ruby',
+ 'station_route_name',
+ 'park_id',
+ 'operator_id',
+ 'station_latitude',
+ 'station_longitude',
+ ]));
+ });
+
+ return redirect()->route('stations')->with('success', '更新しました。');
}
- /**
- * 詳細
- */
- public function info($id)
- {
- $station = Station::findOrFail($id);
- return view('admin.stations.info', compact('station'));
- }
/**
- * 削除
+ * 削除(単一/複数対応)
*/
public function delete(Request $request)
{
- $ids = $request->input('pk'); // 複数ID対応
+ $ids = [];
- if (!empty($ids)) {
- Station::destroy($ids);
- return redirect()->route('stations')->with('success', '削除しました');
+ if ($request->filled('id')) {
+ $ids[] = (int) $request->input('id');
}
- return redirect()->route('stations')->with('error', '削除対象が見つかりません');
+ if (is_array($request->input('pk'))) {
+ $ids = array_merge($ids, $request->input('pk'));
+ }
+
+ $ids = array_values(array_unique(array_map('intval', $ids)));
+
+ if (empty($ids)) {
+ return back()->with('error', '削除対象が選択されていません。');
+ }
+
+ Station::whereIn('station_id', $ids)->delete();
+
+ return redirect()->route('stations')->with('success', '削除しました');
}
+
/**
* CSVインポート(仮)
*/
diff --git a/app/Models/Station.php b/app/Models/Station.php
index b10b994..f6b87c6 100644
--- a/app/Models/Station.php
+++ b/app/Models/Station.php
@@ -15,5 +15,12 @@ class Station extends Model
'station_name_ruby',
'station_route_name',
'operator_id',
+ 'station_latitude', // ← 緯度
+ 'station_longitude', // ← 経度
];
+ public function park()
+ {
+ return $this->belongsTo(Park::class, 'park_id', 'park_id');
+ }
+
}
diff --git a/resources/lang/ja/validation.php b/resources/lang/ja/validation.php
index 542e34e..9fcc95a 100644
--- a/resources/lang/ja/validation.php
+++ b/resources/lang/ja/validation.php
@@ -254,6 +254,9 @@ return [
'user_categoryid' => '利用者分類ID',
'pplace_id' => '駐輪車室ID',
'price' => '駐輪料金(税込)',
+ 'floor_sort' => '階数ソート順',
+
+
// SWA-59
'ope_id' => 'オペレータID',
// 'ope_id' => 'オペレータ名',
@@ -423,6 +426,17 @@ return [
'edit_master' => 'マスタ編集',
'web_master' => 'ウェブ参照マスタ',
'auto_change_date' => 'ウェブ参照マスタ自動切り替え日時',
+//SWA-65
+ 'station_id' => '近傍駅ID',
+ 'created_at' => '登録日時',
+ 'updated_at' => '更新日時',
+ 'park_id' => '駐輪場ID',
+ 'station_neighbor_station' => '近傍駅',
+ 'station_name_ruby' => '近傍駅ふりがな',
+ 'station_route_name' => '路線名',
+ 'station_latitude' => '近傍駅座標(緯度)',
+ 'station_longitude' => '近傍駅座標(経度)',
+ 'operator_id' => '更新オペレータID',
diff --git a/resources/views/admin/ptypes/_form.blade.php b/resources/views/admin/ptypes/_form.blade.php
index 5ec2822..14715b4 100644
--- a/resources/views/admin/ptypes/_form.blade.php
+++ b/resources/views/admin/ptypes/_form.blade.php
@@ -1,62 +1,102 @@
+{{-- アラート --}}
@if(Session::has('success'))
{{ Session::get('success') }}
-@elseif(Session::has('error'))
+@endif
+
+@if($errors->any())
-
{{__('誤差')}}:
- {!! Session::get('error') !!}
-
-@elseif(isset($errorMsg))
-
-
-
{{__('誤差')}}:
- {!! $errorMsg !!}
+
{{ __('入力内容に不備があります:') }}
+
+ @foreach($errors->all() as $error)
+ - {{ $error }}
+ @endforeach
+
@endif
+ {{-- ▼ 駐輪分類ID(編集時のみ表示) --}}
+ @if($isEdit && isset($record->ptype_id))
+ @endif
+
+ {{-- ▼ 駐輪分類名 --}}
+
+ {{-- ▼ 階数ソート順 --}}
+
+ {{-- ▼ 備考 --}}
+
+ {{-- ▼ 下部ボタン --}}
+
+
+
+ {{-- 登録ボタン --}}
+ @if($isEdit)
+
+ @else
+
+ @endif
+
+ {{-- 削除ボタン(編集時のみ表示) --}}
+ @if($isEdit)
+
+ @endif
+
+
+
+
-{{-- ▼ 下部ボタン --}}
-
- {{-- 登録ボタン --}}
-
- {{-- 削除ボタン(編集画面のみ表示) --}}
- @if(!empty($ptype_id))
-
-
- @endif
-
diff --git a/resources/views/admin/ptypes/add.blade.php b/resources/views/admin/ptypes/add.blade.php
index e542e26..9f00933 100644
--- a/resources/views/admin/ptypes/add.blade.php
+++ b/resources/views/admin/ptypes/add.blade.php
@@ -1,6 +1,6 @@
@extends('layouts.app')
-@section('title', '[東京都|〇〇駐輪場] 駐輪分類マスタ')
+@section('title', '新規')
@section('content')
@@ -8,14 +8,13 @@
@@ -31,11 +30,9 @@
diff --git a/resources/views/admin/ptypes/edit.blade.php b/resources/views/admin/ptypes/edit.blade.php
index 06ef475..7ed2341 100644
--- a/resources/views/admin/ptypes/edit.blade.php
+++ b/resources/views/admin/ptypes/edit.blade.php
@@ -1,5 +1,5 @@
@extends('layouts.app')
-@section('title', '[東京都|〇〇駐輪場] 駐輪分類マスタ')
+@section('title', '編集')
@section('content')
@@ -21,23 +21,26 @@
-
-
-
-
+
+
+
+
-
+ {{-- Delete Form --}}
+
-
-
+
+
@endsection
diff --git a/resources/views/admin/ptypes/info.blade.php b/resources/views/admin/ptypes/info.blade.php
deleted file mode 100644
index a07d3c5..0000000
--- a/resources/views/admin/ptypes/info.blade.php
+++ /dev/null
@@ -1,47 +0,0 @@
-
-@extends('layouts.app')
-@section('title', '[東京都|〇〇駐輪場] 駐輪分類マスタ')
-
-@section('content')
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-@endsection
diff --git a/resources/views/admin/ptypes/list.blade.php b/resources/views/admin/ptypes/list.blade.php
index c6d2177..1e06efb 100644
--- a/resources/views/admin/ptypes/list.blade.php
+++ b/resources/views/admin/ptypes/list.blade.php
@@ -1,8 +1,7 @@
@extends('layouts.app')
-@section('title', '[東京都|〇〇駐輪場] 駐輪分類マスタ')
+@section('title', '駐輪分類マスタ')
@section('content')
-{{-- ▼ コンテンツヘッダー(パンくず) --}}