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