Laravel Eloquent 访问原始文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19851325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Eloquent Accessing Original
提问by Wistar
I trying to get a value from an object I get from one of my model. It only returns me the attributes which is not what I want because it does not correspond to what is in my table. I want to access the original array.
我试图从我从我的一个模型中获得的对象中获取一个值。它只返回我不想要的属性,因为它与我的表中的内容不对应。 我想访问原始数组。
I did:
我做了:
$entries = Model::where('A', $A)->where('B', $B)->get();
@Foreach ($entries as $entry)
$entry->id
$entry->name
@Endforeach
I tried to add ->original
but it either doesn't work.
我试图添加,->original
但它要么不起作用。
Here's partially the first entry of my var_dump($entries)
这是我的第一个条目的一部分 var_dump($entries)
(
[items:protected] => Array
(
[0] => App\Models\TableA Object
(
[table:protected] => Table A
[primaryKey] => id
[connection:protected] =>
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 1
[name] => 2
)
[original:protected] => Array
(
[id] => 1
[name] => 1
)
回答by Rob Gordijn
When retrieving the original value of an Eloquent model attribute, you can use
getOriginal($key)
在检索 Eloquent 模型属性的原始值时,您可以使用
getOriginal($key)
Reference:
参考:
回答by kamlesh.bar
For laravel 4.2 and on
对于 Laravel 4.2 及更高版本
$entries->toArray()
Will provide model attributes only.
将仅提供模型属性。