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?

Laravelのviewとgetの使い分け

0
Posted at

Laravelのviewとgetの使い分けについて学んだのでまとめる。

viewを使うシーン

Controllerを使わない静的なページを作成するとき。
見るだけ。
機能的な部分がないHTMLだけ、みたいな。

Controllerを使わず、表示するだけの静的ページを作成するとき。

見るだけのページ
ロジックなし
DBアクセスなし
フォーム処理なし
将来的にも機能追加の予定がない

その場合は以下のように書く。

Route::view('/','index');

getを使うシーン

静的ではなく、何かしらの処理・機能が関わるページを表示するとき。

Controllerを使う
セッションを扱う
バリデーション
DB取得
フォーム(お問い合わせ・検索など)
完了画面・確認画面

Route::get('/contact', [ContactController::class, 'index']);

まとめ

view は「楽をするための省略記法」
get は「処理を挟める正式ルート」

状況 選択
完全に固定ページ Route::view()
今は静的だが拡張予定 Route::get()
フォーム・検索・一覧 Route::get()
管理画面 Route::get()
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?