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.
Here's partially the first entry of my 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
)
Accessors and mutators allow you to format Eloquent attributes when retrieving them from a model or setting their value. For example, you may want to use the Laravel encrypter to encrypt a value while it is stored in the database, and then automatically decrypt the attribute when you access it on an Eloquent model.
Searching Eloquent models Imagine you need to provide a search for users. Using Eloquent you can perform a search like this: User::query() ->where('name', 'LIKE', "%{$searchTerm}%") ->orWhere('email', 'LIKE', "%{$searchTerm}%") ->get();
Eloquent is an ORM, which means can automatically handle the relationships of your models for you. You can retrieve related models without writing complex queries. You can even retrieve database information without any kind of database knowledge at all.
A one-to-one polymorphic relationship is a situation where one model can belong to more than one type of model but on only one association. A typical example of this is featured images on a post and an avatar for a user. The only thing that changes however is how we get the associated model by using morphOne instead.
When retrieving the original value of an Eloquent model attribute, you can use
getOriginal($key)
Reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With