チェックイン修正を雑に書いた

これ日時はいじれないほうが良い気がするな
This commit is contained in:
shibafu 2018-01-04 16:53:33 +09:00
parent 7a3a1c1ada
commit 2fe3d7ac49
5 changed files with 147 additions and 6 deletions

View File

@ -69,14 +69,42 @@ class EjaculationController extends Controller
return view('ejaculation.show')->with(compact('user', 'ejaculation', 'ejaculatedSpan'));
}
public function edit()
public function edit($id)
{
// TODO: not implemented
$ejaculation = Ejaculation::findOrFail($id);
return view('ejaculation.edit')->with(compact('ejaculation'));
}
public function update()
public function update(Request $request, $id)
{
// TODO: not implemented
$ejaculation = Ejaculation::findOrFail($id);
$inputs = $request->all();
if ($request->has('note')) {
$inputs['note'] = str_replace(["\r\n", "\r"], "\n", $inputs['note']);
}
Validator::make($inputs, [
'date' => 'required|date_format:Y/m/d',
'time' => 'required|date_format:H:i',
'note' => 'nullable|string|max:500',
])->after(function ($validator) use ($id, $request, $inputs) {
// 日時の重複チェック
if (!$validator->errors()->hasAny(['date', 'time'])) {
$dt = $inputs['date'] . ' ' . $inputs['time'];
if (Ejaculation::where(['user_id' => Auth::id(), 'ejaculated_date' => $dt])->where('id', '<>', $id)->count()) {
$validator->errors()->add('datetime', '既にこの日時にチェックインしているため、登録できません。');
}
}
})->validate();
$ejaculation->fill([
'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']),
'note' => $inputs['note'] ?? '',
'is_private' => $request->has('is_private') ?? false
])->save();
return redirect()->route('checkin.show', ['id' => $ejaculation->id])->with('status', 'チェックインを修正しました!');
}
public function destroy($id)

View File

@ -0,0 +1,111 @@
@extends('layouts.base')
@section('content')
<div class="container">
<h2>チェックインの修正</h2>
<hr>
<div class="row justify-content-center mt-5">
<div class="col-lg-6">
<form method="post" action="{{ route('checkin.update', ['id' => $ejaculation->id]) }}">
{{ method_field('PUT') }}
{{ csrf_field() }}
<div class="form-row">
<div class="form-group col-sm-6">
<label for="date"><span class="oi oi-calendar"></span> 日付</label>
<input id="date" name="date" type="text" class="form-control {{ $errors->has('date') || $errors->has('datetime') ? ' is-invalid' : '' }}"
pattern="^20[0-9]{2}/(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])$" value="{{ old('date') ?? $ejaculation->ejaculated_date->format('Y/m/d') }}" required>
@if ($errors->has('date'))
<div class="invalid-feedback">{{ $errors->first('date') }}</div>
@endif
</div>
<div class="form-group col-sm-6">
<label for="time"><span class="oi oi-clock"></span> 時刻</label>
<input id="time" name="time" type="text" class="form-control {{ $errors->has('time') || $errors->has('datetime') ? ' is-invalid' : '' }}"
pattern="^([01][0-9]|2[0-3]):[0-5][0-9]$" value="{{ old('time') ?? $ejaculation->ejaculated_date->format('H:i') }}" required>
@if ($errors->has('time'))
<div class="invalid-feedback">{{ $errors->first('time') }}</div>
@endif
</div>
@if ($errors->has('datetime'))
<div class="form-group col-sm-12" style="margin-top: -1rem;">
<small class="text-danger">{{ $errors->first('datetime') }}</small>
</div>
@endif
</div>
{{--
<div class="form-row">
<div class="form-group col-sm-12">
<label for="tags"><span class="oi oi-tags"></span> タグ</label>
<input id="tags" type="text" class="form-control" placeholder="未実装です" disabled>
<small class="form-text text-muted">
スペース区切りで複数入力できます。
</small>
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-12">
<label for="link"><span class="oi oi-link-intact"></span> オカズリンク</label>
<input id="link" type="text" class="form-control" placeholder="https://...">
<small class="form-text text-muted">
オカズのURLを貼り付けて登録することができます。
</small>
</div>
<div class="form-group col-sm-12 d-none">
<div class="card">
<div class="card-header">このオカズで合っていますか?</div>
<div class="card-body">
<div class="d-flex mb-4">
<img src="holder.js/128x128" alt="" class="rounded">
<div class="align-self-center ml-2 mr-auto">
<p class="mb-1">タイトル</p>
<small class="text-muted">概要</small>
</div>
</div>
<a href="#" class="btn btn-success"><span class="oi oi-check"></span> 決定</a>
<a href="#" class="btn btn-outline-secondary">キャンセル</a>
</div>
</div>
</div>
</div>
--}}
<div class="form-row">
<div class="form-group col-sm-12">
<label for="note"><span class="oi oi-comment-square"></span> ノート</label>
<textarea id="note" name="note" class="form-control {{ $errors->has('note') ? ' is-invalid' : '' }}" rows="4">{{ old('note') ?? $ejaculation->note }}</textarea>
<small class="form-text text-muted">
最大 500 文字
</small>
@if ($errors->has('note'))
<div class="invalid-feedback">{{ $errors->first('note') }}</div>
@endif
</div>
</div>
<div class="form-row mt-4">
<p>オプション</p>
<div class="form-group col-sm-12">
<div class="form-check">
<label class="custom-control custom-checkbox">
<input name="is_private" type="checkbox" class="custom-control-input" {{ (is_bool(old('is_private')) ? old('is_private') : $ejaculation->is_private) ? 'checked' : '' }}>
<span class="custom-control-indicator"></span>
<span class="custom-control-description">
<span class="oi oi-lock-locked"></span> このチェックインを非公開にする
</span>
</label>
</div>
</div>
</div>
<div class="text-center">
<button class="btn btn-primary" type="submit">チェックイン</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@push('script')
@endpush

View File

@ -28,7 +28,7 @@
<h5>{{ $ejaculatedSpan ?? '精通' }} <small class="text-muted">{{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}</small></h5>
@if ($user->isMe())
<div>
<a class="text-secondary timeline-action-item" href="#"><span class="oi oi-pencil" data-toggle="tooltip" data-placement="bottom" title="修正"></span></a>
<a class="text-secondary timeline-action-item" href="{{ route('checkin.edit', ['id' => $ejaculation->id]) }}"><span class="oi oi-pencil" data-toggle="tooltip" data-placement="bottom" title="修正"></span></a>
<a class="text-secondary timeline-action-item" href="#" data-toggle="modal" data-target="#deleteCheckinModal" data-id="{{ $ejaculation->id }}" data-date="{{ $ejaculation->ejaculated_date }}"><span class="oi oi-trash" data-toggle="tooltip" data-placement="bottom" title="削除"></span></a>
</div>
@endif

View File

@ -14,7 +14,7 @@
<h5>{{ $ejaculation->ejaculated_span ?? '精通' }} <a href="{{ route('checkin.show', ['id' => $ejaculation->id]) }}" class="text-muted"><small>{{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}</small></a></h5>
@if ($user->isMe())
<div>
<a class="text-secondary timeline-action-item" href="#"><span class="oi oi-pencil" data-toggle="tooltip" data-placement="bottom" title="修正"></span></a>
<a class="text-secondary timeline-action-item" href="{{ route('checkin.edit', ['id' => $ejaculation->id]) }}"><span class="oi oi-pencil" data-toggle="tooltip" data-placement="bottom" title="修正"></span></a>
<a class="text-secondary timeline-action-item" href="#" data-toggle="modal" data-target="#deleteCheckinModal" data-id="{{ $ejaculation->id }}" data-date="{{ $ejaculation->ejaculated_date }}"><span class="oi oi-trash" data-toggle="tooltip" data-placement="bottom" title="削除"></span></a>
</div>
@endif

View File

@ -26,6 +26,8 @@ Route::middleware('auth')->group(function () {
Route::get('/checkin', 'EjaculationController@create')->name('checkin');
Route::post('/checkin', 'EjaculationController@store')->name('checkin');
Route::get('/checkin/{id}', 'EjaculationController@show')->name('checkin.show');
Route::get('/checkin/{id}/edit', 'EjaculationController@edit')->name('checkin.edit');
Route::put('/checkin/{id}', 'EjaculationController@update')->name('checkin.update');
Route::delete('/checkin/{id}', 'EjaculationController@destroy')->name('checkin.destroy');
});