首页 > laravel的request里的get和input有区别嘛?

laravel的request里的get和input有区别嘛?

public function foo(Request $request)
{
    $foo = $request->get('a');
    
    $foo = $request->input('a');
}

这里用get和input有区别嘛?


不一样。

大概看了下input获取到数组后简单做了下取出操作,
get有一套更完善的取出机制,也有很多抛异常操作。

具体LZ可以去翻翻源代码看看:
input方法在:/vendor/laravel/framework/src/Illuminate/Http/Request.php
get方法在:/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/ParameterBag.php

PS,我手上目前是4.2

【热门文章】
【热门文章】