取得输入数据

取得特定输入数据

你可以通过 IlluminateHttpRequest 的实例,经由几个简洁的方法取得所有的用户输入数据。不需要担心发出请求时使用的 HTTP 请求,取得输入数据的方式都是相同的。

$name = Request::input("name");

取得特定输入数据,若没有则取得默认值

$name = Request::input("name", "Sally");

确认是否有输入数据

if (Request::has("name"))
{
    //
}

取得所有发出请求时传入的输入数据

$input = Request::all();

取得部分发出请求时传入的输入数据

$input = Request::only("username", "password");

$input = Request::except("credit_card");

如果是「数组」形式的输入数据,可以使用「点」语法取得数组:

$input = Request::input("products.0.name");

文章导航