public function test()
{
$test = request()->input(‘test‘,‘this is test !!!‘);
dd($test);
}
请求时,没有test
参数字段时,$test=‘this is test !!!‘
请求时,test参数为空时,$test
为空,而不是this is test !!!
感觉 input() 方法第二个参数,没什么用,可以用 ??
替代
这样没有传test
参数字段或test
参数为空,都会取到默认值
public function test()
{
$test = request()->input(‘test‘) ?? ‘this is test !!!‘;
dd($test);
}
原文:https://www.cnblogs.com/mg007/p/14120949.html