1
0

More than 1 year has passed since last update.

PHP laravel 任意のルーティングパラメーターを設定する

Posted at

概要

  • laravelで任意のルーティングパラメーターを設定する方法をまとめる。

方法

  • 絞り込みなどでURLに任意のパラメーターを含めたいとき下記ようにルーティングを記載する(yearとmonthは合ってもなくても当該のページが表示できる。)

    web.php
    // シングルアクションコントローラーのコントローラー指定方法なので通常とは異なる
    Route::get('/Foo/Bar/{year?}/{month?}', HogeHogeController::class)
    
  • 上記のようにしておけば/Foo/Berにアクセスしても/Foo/Bar/2022/10にアクセスしても同じページが開く。

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