我想知道您是否可以在 php(更明确地 Laravel)中键入一组模型。
一个代码示例:
use App\User;
public function index(User $user)
{
// do something with the user
}
我的问题是,有没有办法对用户模型数组进行类型提示:
use App\User;
public function index(array User $users) //this is wrong ..
{
// do something with the users
}
最佳答案
不,你不能这样做 。您能做的最好的事情是将参数类型提示为数组。您可以在此处阅读有关 PHP 中类型提示的更多信息:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
更新
在 PHP 5.6+ 中,您可以使用可变长度参数列表来实现您想要的。检查 answer below
关于php - 类型提示模型数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32050599/