Webhook識別名重複チェック

This commit is contained in:
shibafu 2020-07-23 22:57:21 +09:00
parent 059c6d69cf
commit bbbea73a05
2 changed files with 14 additions and 2 deletions

View File

@ -87,7 +87,16 @@ class SettingController extends Controller
public function storeWebhooks(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:255'
'name' => [
'required',
'string',
'max:255',
Rule::unique('checkin_webhooks', 'name')->where(function ($query) {
return $query->where('user_id', Auth::id());
})
]
], [], [
'name' => '名前'
]);
if (Auth::user()->checkinWebhooks()->count() >= CheckinWebhook::PER_USER_LIMIT) {

View File

@ -20,8 +20,11 @@
{{ csrf_field() }}
<div class="form-group">
<label for="name">名前 (メモ)</label>
<input id="name" class="form-control" name="name" type="text" required>
<input id="name" class="form-control {{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" type="text" required>
<small class="form-text text-muted">後で分かるように名前を付けておいてください。</small>
@if ($errors->has('name'))
<div class="invalid-feedback">{{ $errors->first('name') }}</div>
@endif
</div>
<button class="btn btn-primary" type="submit">新規作成</button>
</form>