1
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?

Laravel + HTML 基礎:GET と aタグの正しい使い分け

Last updated at Posted at 2025-08-13

1. 前提

▪️ GET はサーバーの状態を変えない「参照系」リクエストで使う

▪️ aタグ はページ遷移(リンク)に使う

▪️ form + GET は「検索フォーム」や「フィルタ」のように入力フォームの値をURLに載せたい時だけ使う

2. 基本ルール

✅ aタグを使うケース

▪️ 単純なページ遷移(クリックで別URLへ移動するだけ)

▪️ Laravelのroute()でURLを生成できる場合

▪️ 見た目がボタンでも、機能的に「リンク」のとき


例:

<a href="{{ route('tasks.edit', ['task' => $task->id]) }}"
   class="btn btn-primary">
    編集
</a>

✅ form + GET を使うケース

▪️ 検索フォーム

▪️ 並び替えや絞り込みフォーム

▪️ 入力値をクエリパラメータとしてURLに残したい場合


例:

<form action="{{ route('tasks.index') }}" method="GET">
    @csrf
    <input type="text" name="keyword" placeholder="キーワード">
    <button type="submit">検索</button>
</form>

送信後URL例:

/tasks?keyword=Laravel

❌ form + GET を使わないケース

▪️ 単なるページ遷移(aタグで十分)

▪️ サーバー側で状態を変更する処理(POSTを使う)

3. 実務での選び方

▪️ 画面遷移だけ → aタグ

▪️ 検索や条件指定 → form + GET

▪️ データ更新 → form + POST

▪️ 「見た目がボタンだからform」はNG。意味論的に正しいタグを使う。

4. まとめ表

動作 適切な方法
ページ遷移 aタグ
検索条件送信 form + GET
データ登録/更新 form + POST
見た目だけボタン aタグ + CSS
1
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
1
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?