我想使用 mysql where 命令从 laravel 中的数据库返回一个值,但它给出了空结果
这段代码给出了结果,但我不想这样
$data = admin::all();
foreach ($data as $dat) {
echo $dat->name;
echo $dat->email;
}
我想这样做,但结果是空的
$data = admin::where('username', '=', $uname);
foreach ($data as $dat) {
echo $dat->name;
echo $dat->email;
}
最佳答案
where()
仅为您构建查询。您仍然需要以某种方式检索结果。方法是 get()
方法。像这样:
$data = admin::where('username', '=', $uname)->get();
关于php - 我想使用 mysql where 命令从 laravel 中的数据库返回一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37264193/