laravel request input() 默認值問題


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);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM