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 3 years have passed since last update.

必須パラメータと任意パラメータ

Last updated at Posted at 2020-03-03

#Route::get('hello/{name}',function ($name) { });

題のような必須パラメータはパラメータの部分


Route::get('hello/{ここのこと}',function ~~~

が空の時はサイトがNOT FOUNDになる。
それでは、実用性があまりないですよね。

そんな時、空でもエラー出なく表示させるために任意パラメータを使います。


Route::get('hello/{name?},function ($name='no name.') { 
    <p>こんにちは、{$name}さん</p>
});

パラメータの後に、?をつけて
URLのパラメータの部分が空だった時に代入する内容を[’’]で囲むと任意パラメータになります。

すると結果は

こんにちはno nameさん

こうなります。

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?