这是我的代码:
$data = Model::where('condition', $value)->get();
print_r($data);
如何唯有 Eloquent 才能出结果?它得到了不必要的 key 。
$data['connection']
$data['guarded']
$data['etc.. etc etc...]
最佳答案
使用它从 Eloquent 中获取所有列而无需任何额外数据:
$data = Model::where('condition', $value)->get()->toArray();
或者,如果您只需要一些键:
$data = Model::where('condition', $value)->get('valueIneed1', 'valueIneed2', 'valueIneed3')->toArray();
当你使用 get()
时,你会得到一个 eloquent collection
。其中包含大量附加数据。
关于php - Laravel 5 Eloquent 只得到必要的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37021777/