0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Laravel】リソースコントローラー削除&編集機能

Last updated at Posted at 2024-04-20

削除機能

編集機能

削除機能、編集機能時に@method('DELETE')/@method('PATCH')を記載する理由

HTMLフォームはGET or POSTのみが許可されている。
だからフォームのDELETEリクエストを使う場合は、擬似的に使う方法をとる。

@method('DELETE')の例

<form action="{{ route('spending.destroy', ['spending' => $spending['id']]) }}" method="post">
    @csrf
    <!-- HTMLフォームはGET or POSTのみが許可されている。
    だから↓フォームのDELETEリクエストを使う場合は、擬似的に使う方法をとる↓。 -->
    @method('DELETE')
    <button type="submit" class="btn btn-danger ml-5">削除</button>
</form>

@method('PATCH')の例

<form action="{{ route('spending.update', ['spending' => $spending['id']]) }}" method="post" class="mt-5 date_option">
    @csrf
    @method('PATCH')
    <div class="form-group">
        <label for="date">日付</label>
        <input type="date" id="date" name="date" value="{{ $spending['date'] }}" class="date_border form-control">
    </div>
    <div class="form-group">
        <label for="title">タイトル(20文字以内)</label>
        <input type="text" id="title" name="title" value="{{ $spending['title'] }}" class="form-control">
    </div>
    <div class="form-group">
        <label for="amount">支出金額(11桁以内)</label>
        <input type="number" id="amount" name="amount" value="{{ $spending['amount'] }}" class="form-control">
    </div>
    <div class="mt-4">
        <button type="submit" class="btn btn-primary">更新</button>
    </div>
</form>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?