我有以下控制器,它应该返回所有尚未验证的用户。
public function getUserRequests()
{
$userRequests = User::where('status' ,"Not Verified");
foreach($userRequests as $user)
{
echo $user->name;
}
}
输出是空白页面。我该怎么办?
答案 0 :(得分:3)
您应该使用get()
方法获取数据:
$userRequests = User::where('status' ,"Not Verified")->get();
答案 1 :(得分:2)
试试这个:您需要使用get()
方法来获取数据。
$userRequests = User::where('status', '=', 'Not Verified')->get();
答案 2 :(得分:0)
您必须使用
get()
方法返回数据。
所以,你的功能应该是这样的。
public function getUserRequests()
{
$userRequests = User::where('status', "Not Verified")->get();
foreach($userRequests as $user)
{
echo $user->name;
}
}
答案 3 :(得分:0)
非常简单的一种方法是,
public function getUserRequests()
{
$userRequests = User::where('status' ,"Not Verified")->get(['name]);
foreach($userRequests as $user)
{
echo $user->name;
}
}
或
public function getUserRequests()
{
$userRequests = User::where('status' ,"Not Verified")->select('name')->get();
foreach($userRequests as $user)
{
echo $user->name;
}
}