This commit is contained in:
parent
3b7ae71d56
commit
2b8f80fe50
@ -38,72 +38,91 @@ class PsectionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// 新規追加
|
||||
/**
|
||||
* 車種区分マスタ:新規登録(画面/処理)
|
||||
*/
|
||||
public function add(Request $request)
|
||||
{
|
||||
if ($request->isMethod('post')) {
|
||||
$validated = $request->validate([
|
||||
// 'psection_id' は自動採番なので不要
|
||||
'psection_subject' => 'required|string|max:255',
|
||||
if ($request->isMethod('get')) {
|
||||
// GET:新規画面を表示
|
||||
return view('admin.psection.add', [
|
||||
'isEdit' => false, // フォーム判定用
|
||||
'record' => new Psection(), // ← ★★ これを渡すことで $record が使える
|
||||
]);
|
||||
|
||||
Psection::create($validated);
|
||||
|
||||
return redirect()->route('psections')->with('success', '車室区分を追加しました');
|
||||
}
|
||||
|
||||
// GET の場合は空のモデルを渡してフォームを表示
|
||||
return view('admin.psection.add', ['psection' => new Psection()]);
|
||||
// POST:バリデーション
|
||||
$validated = $request->validate([
|
||||
// 'psection_id' は自動採番
|
||||
'psection_subject' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
// 登録処理
|
||||
Psection::create($validated);
|
||||
|
||||
// 完了メッセージ+一覧へ戻る
|
||||
return redirect()->route('psections')->with('success', '登録しました。');
|
||||
}
|
||||
|
||||
// 編集
|
||||
|
||||
/**
|
||||
* 車種区分マスタ:編集(画面/処理)
|
||||
*/
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
// 主キーで検索(見つからない場合は 404)
|
||||
$psection = Psection::findOrFail($id);
|
||||
// 主キーで検索(見つからない場合は404)
|
||||
$record = Psection::findOrFail($id);
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
// バリデーション
|
||||
$validated = $request->validate([
|
||||
'psection_subject' => 'required|string|max:255',
|
||||
if ($request->isMethod('get')) {
|
||||
// 編集画面表示
|
||||
return view('admin.psection.edit', [
|
||||
'isEdit' => true, // ← ★ Blade 側のフォームで新規/編集を判定するため
|
||||
'record' => $record, // ← ★ _form.blade.php で使用する
|
||||
]);
|
||||
|
||||
// データ更新
|
||||
$psection->update($validated);
|
||||
|
||||
// 成功メッセージ & リダイレクト
|
||||
return redirect()->route('psections')->with('success', '車種区分を更新しました');
|
||||
}
|
||||
|
||||
// 編集画面を表示
|
||||
return view('admin.psection.edit', compact('psection'));
|
||||
}
|
||||
// POST時:バリデーション
|
||||
$validated = $request->validate([
|
||||
'psection_subject' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
// データ更新
|
||||
$record->update($validated);
|
||||
|
||||
// 詳細(info)
|
||||
public function info(Request $request, $id)
|
||||
{
|
||||
$psection = Psection::findOrFail($id);
|
||||
return view('admin.psection.info', compact('psection'));
|
||||
// 成功メッセージ & リダイレクト
|
||||
return redirect()->route('psections')->with('success', '更新しました。');
|
||||
}
|
||||
|
||||
// 削除
|
||||
/**
|
||||
* 削除(単一/複数対応)
|
||||
*/
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$arr_pk = $request->get('pk');
|
||||
$ids = [];
|
||||
|
||||
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 (Psection::whereIn('psection_id', $arr_pk)->delete()) {
|
||||
return redirect()->route('psections')->with('success', __("削除が完了しました。"));
|
||||
} else {
|
||||
return redirect()->route('psections')->with('error', __('削除に失敗しました。'));
|
||||
}
|
||||
// 一覧画面からの複数削除チェックボックス対応
|
||||
if (is_array($request->input('pk'))) {
|
||||
$ids = array_merge($ids, $request->input('pk'));
|
||||
}
|
||||
return redirect()->route('psections')->with('error', __('削除するデータを選択してください。'));
|
||||
|
||||
// 重複削除・無効値除去
|
||||
$ids = array_values(array_unique(array_map('intval', $ids)));
|
||||
|
||||
// 削除対象がない場合
|
||||
if (empty($ids)) {
|
||||
return back()->with('error', '削除対象が選択されていません。');
|
||||
}
|
||||
|
||||
// 削除実行
|
||||
Psection::whereIn('psection_id', $ids)->delete();
|
||||
|
||||
// 完了メッセージ+リダイレクト
|
||||
return redirect()->route('psections')->with('success', '削除しました。');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ return [
|
||||
'park_id' => '駐輪場ID',
|
||||
// 'park_id' => '駐輪場名',
|
||||
'psection_id' => '車種区分ID',
|
||||
'psection_subject' => '車種区分',
|
||||
'psection_subject' => '車種区分名',
|
||||
'price_ptypeid' => '駐輪分類ID',
|
||||
'user_categoryid' => '利用者分類ID',
|
||||
'pplace_id' => '駐輪車室ID',
|
||||
|
||||
@ -284,23 +284,23 @@
|
||||
<div class="row mt-4">
|
||||
<div class="form-group col-md-10 d-flex align-items-center gap-2 justify-content-start">
|
||||
|
||||
{{-- 登録ボタン --}}
|
||||
@if($isEdit)
|
||||
<button type="button" id="register_edit" class="btn btn-lg btn-success mr-2">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
@else
|
||||
<button type="button" id="register" class="btn btn-lg btn-success mr-2 register">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
@endif
|
||||
{{-- 登録ボタン --}}
|
||||
@if($isEdit)
|
||||
<button type="button" id="register_edit" class="btn btn-lg btn-success mr-2">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
@else
|
||||
<button type="button" id="register" class="btn btn-lg btn-success mr-2 register">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
@endif
|
||||
|
||||
{{-- 削除ボタン(編集時のみ表示) --}}
|
||||
@if($isEdit)
|
||||
<button type="button" id="delete_edit" class="btn btn-lg btn-danger">
|
||||
{{ __('削除') }}
|
||||
</button>
|
||||
@endif
|
||||
{{-- 削除ボタン(編集時のみ表示) --}}
|
||||
@if($isEdit)
|
||||
<button type="button" id="delete_edit" class="btn btn-lg btn-danger">
|
||||
{{ __('削除') }}
|
||||
</button>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,63 +1,77 @@
|
||||
{{-- アラート --}}
|
||||
@if(Session::has('success'))
|
||||
<div class="alert alert-success alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
{{ Session::get('success') }}
|
||||
</div>
|
||||
@elseif(Session::has('error'))
|
||||
@endif
|
||||
|
||||
@if($errors->any())
|
||||
<div class="alert alert-danger alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h4><i class="icon fa fa-ban"></i> {{__('誤差')}}:</h4>
|
||||
{!! Session::get('error') !!}
|
||||
</div>
|
||||
@elseif(isset($errorMsg))
|
||||
<div class="alert alert-danger alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h4><i class="icon fa fa-ban"></i> {{__('誤差')}}:</h4>
|
||||
{!! $errorMsg !!}
|
||||
<h4><i class="icon fa fa-ban"></i> {{ __('入力内容に不備があります:') }}</h4>
|
||||
<ul>
|
||||
@foreach($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="card-body">
|
||||
{{-- 車室区分ID --}}
|
||||
{{-- ▼ 車種区分ID(編集時のみ表示) --}}
|
||||
@if($isEdit && isset($record))
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">車室区分ID</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="psection_id" class="form-control"
|
||||
value="{{ old('psection_id', $psection->psection_id ?? '') }}"
|
||||
@if(isset($psection)) readonly @endif>
|
||||
<div class="col-3">
|
||||
<label>{{ __('車種区分ID') }}</label>
|
||||
</div>
|
||||
<div class="col-9">
|
||||
<input type="text"
|
||||
name="psection_id"
|
||||
value="{{ $record->psection_id }}"
|
||||
class="form-control form-control-lg"
|
||||
readonly>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- 車室区分名 --}}
|
||||
{{-- ▼ 車種区分名 --}}
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">車室区分名<span class="text-danger">*</span></label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="psection_subject" class="form-control"
|
||||
value="{{ old('psection_subject', $psection->psection_subject ?? '') }}" required>
|
||||
<div class="col-3">
|
||||
<label class="required">{{ __('車種区分名') }}</label>
|
||||
</div>
|
||||
<div class="col-9">
|
||||
<input type="text"
|
||||
name="psection_subject"
|
||||
value="{{ old('psection_subject', $record->psection_subject ?? '') }}"
|
||||
class="form-control form-control-lg"
|
||||
placeholder="{{ __('validation.attributes.psection_subject') }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- ▼ 下部ボタン --}}
|
||||
<div class="form-group row">
|
||||
<div class="form-group col-12 d-flex gap-2 mt-4">
|
||||
{{-- 登録ボタン --}}
|
||||
<button type="submit"
|
||||
class="btn btn-lg btn-success mr-2"
|
||||
onclick="return confirm('登録してよろしいですか?');">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
<div class="row mt-4">
|
||||
<div class="form-group col-md-10 d-flex align-items-center gap-2 justify-content-start">
|
||||
|
||||
{{-- 削除ボタン(編集画面のみ表示) --}}
|
||||
@if(!empty($psection->psection_id))
|
||||
</form>
|
||||
<form method="POST" action="{{ route('psections_delete') }}"
|
||||
onsubmit="return confirm('本当に削除しますか?')" class="d-inline-block mr-2">
|
||||
@csrf
|
||||
<input type="hidden" name="pk" value="{{ $psection->psection_id }}">
|
||||
<button type="submit" class="btn btn-lg btn-danger">{{ __('削除') }}</button>
|
||||
</form>
|
||||
{{-- 登録ボタン --}}
|
||||
@if($isEdit)
|
||||
<button type="button" id="register_edit" class="btn btn-lg btn-success mr-2">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
@else
|
||||
<button type="button" id="register" class="btn btn-lg btn-success mr-2 register">
|
||||
{{ __('登録') }}
|
||||
</button>
|
||||
@endif
|
||||
|
||||
{{-- 削除ボタン(編集時のみ表示) --}}
|
||||
@if($isEdit)
|
||||
<button type="button" id="delete_edit" class="btn btn-lg btn-danger">
|
||||
{{ __('削除') }}
|
||||
</button>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
@extends('layouts.app')
|
||||
@section('title', '[東京都|〇〇駐輪場] 車種区分マスタ')
|
||||
@section('title', '新規')
|
||||
|
||||
@section('content')
|
||||
<!-- Content Header (Page header) -->
|
||||
@ -8,13 +8,13 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-lg-6">
|
||||
<h1 class="m-0 text-dark">新規登録</h1>
|
||||
<h1 class="m-0 text-dark">新規</h1>
|
||||
</div><!-- /.col -->
|
||||
<div class="col-lg-6">
|
||||
<ol class="breadcrumb float-sm-right text-sm">
|
||||
<li class="breadcrumb-item"><a href="./index2.html">ホーム</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('psections') }}">車種区分マスタ</a></li>
|
||||
<li class="breadcrumb-item active">新規登録</li>
|
||||
<li class="breadcrumb-item active">新規</li>
|
||||
</ol>
|
||||
</div><!-- /.col -->
|
||||
</div><!-- /.row -->
|
||||
@ -30,11 +30,9 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<form method="post" action="{{ route('psections_add')}}" enctype="multipart/form-data">
|
||||
<!-- TOKEN FORM -->
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}" >
|
||||
<!-- / .TOKEN FORM -->
|
||||
@include('admin.psection._form',['isEdit'=>0,'isInfo'=>0])
|
||||
<form id="form_add" action="{{ route('psections_add') }}" method="POST">
|
||||
@csrf
|
||||
@include('admin.psection._form', ['isEdit' => false, 'record' => $record])
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', '車種区分マスタ 編集')
|
||||
@section('title', '編集')
|
||||
|
||||
@section('content')
|
||||
<div class="content-header">
|
||||
@ -23,9 +23,20 @@
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="card">
|
||||
<form method="POST" action="{{ route('psections_edit', ['id' => $psection->psection_id]) }}">
|
||||
<form id="form_edit"
|
||||
action="{{ route('psections_edit', ['id' => $record->psection_id]) }}"
|
||||
method="POST">
|
||||
@csrf
|
||||
@include('admin.psection._form',['isEdit'=>1,'isInfo'=>0])
|
||||
@include('admin.psection._form', ['isEdit' => true])
|
||||
</form>
|
||||
|
||||
{{-- Delete Form --}}
|
||||
<form id="form_delete"
|
||||
action="{{ route('psections_delete') }}"
|
||||
method="POST"
|
||||
style="display:none;">
|
||||
@csrf
|
||||
<input type="hidden" name="id" value="{{ $record->psection_id }}">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
@extends('layouts.app')
|
||||
@section('title', '車種区分詳細')
|
||||
@section('content')
|
||||
<div class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-lg-6"><h1 class="m-0 text-dark">車種区分詳細</h1></div>
|
||||
<div class="col-lg-6">
|
||||
<ol class="breadcrumb float-sm-right text-sm">
|
||||
<li class="breadcrumb-item"><a href="{{ url('/home') }}">ホーム</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('psection') }}">車種区分マスタ</a></li>
|
||||
<li class="breadcrumb-item active">詳細</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="form-group">
|
||||
<label>車種区分ID</label>
|
||||
<input type="number" value="{{ $psection->psection_id }}" class="form-control" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>車種区分名</label>
|
||||
<input type="text" value="{{ $psection->psection_subject }}" class="form-control" readonly>
|
||||
</div>
|
||||
<a href="{{ route('psection') }}" class="btn btn-secondary">一覧に戻る</a>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@ -27,8 +27,7 @@
|
||||
{{-- ▼ アクションボタン --}}
|
||||
<div class="mb-3">
|
||||
<a href="{{ route('psections_add') }}" class="btn btn-sm btn-default">新規</a>
|
||||
<button type="submit" form="deleteForm" class="btn btn-sm btn-default ml-2"
|
||||
onclick="return confirm('選択した区分を削除しますか?');">削除</button>
|
||||
<button type="button" class="btn btn-sm btn-default mr10" id="delete">削除</button>
|
||||
</div>
|
||||
|
||||
{{-- ▼ ページネーション --}}
|
||||
@ -55,7 +54,7 @@
|
||||
@endif
|
||||
|
||||
@if ($list->count() > 0)
|
||||
<form id="deleteForm" method="POST" action="{{ route('psections_delete') }}">
|
||||
<form id="form_delete" method="POST" action="{{ route('psections_delete') }}">
|
||||
@csrf
|
||||
|
||||
<div class="table-responsive">
|
||||
@ -99,32 +98,11 @@
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
@else
|
||||
{{-- ▼ データ無し表示 --}}
|
||||
<div class="alert alert-info mt-4">表示するデータがありません。</div>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{{-- ▼ ソート用スクリプト --}}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
document.querySelectorAll("th.sorting, th.sorting_asc, th.sorting_desc").forEach(function(th) {
|
||||
th.addEventListener("click", function() {
|
||||
const sort = this.getAttribute("sort");
|
||||
let sortType = "{{ $sort_type }}";
|
||||
if ("{{ $sort }}" === sort) {
|
||||
sortType = (sortType === "asc") ? "desc" : "asc";
|
||||
} else {
|
||||
sortType = "asc";
|
||||
}
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set("sort", sort);
|
||||
url.searchParams.set("sort_type", sortType);
|
||||
window.location.href = url.toString();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@endsection
|
||||
|
||||
Loading…
Reference in New Issue
Block a user