チェックイン編集画面もタグ登録に対応

This commit is contained in:
shibafu
2018-01-08 08:56:17 +09:00
parent b1dcc36565
commit 24a3b0ebb5
2 changed files with 76 additions and 1 deletions

View File

@@ -54,7 +54,6 @@ class EjaculationController extends Controller
$tag = Tag::firstOrCreate(['name' => $tag]);
$tagIds[] = $tag->id;
}
$ejaculation->tags()->sync($tagIds);
return redirect()->route('checkin.show', ['id' => $ejaculation->id])->with('status', 'チェックインしました!');
@@ -102,6 +101,7 @@ class EjaculationController extends Controller
'time' => 'required|date_format:H:i',
'note' => 'nullable|string|max:500',
'link' => 'nullable|url',
'tags' => 'nullable|string',
])->after(function ($validator) use ($id, $request, $inputs) {
// 日時の重複チェック
if (!$validator->errors()->hasAny(['date', 'time'])) {
@@ -119,6 +119,14 @@ class EjaculationController extends Controller
'is_private' => $request->has('is_private') ?? false
])->save();
$tags = explode(' ', $inputs['tags']);
$tagIds = [];
foreach ($tags as $tag) {
$tag = Tag::firstOrCreate(['name' => $tag]);
$tagIds[] = $tag->id;
}
$ejaculation->tags()->sync($tagIds);
return redirect()->route('checkin.show', ['id' => $ejaculation->id])->with('status', 'チェックインを修正しました!');
}