Wistar
Wistar

Reputation: 3790

Laravel Eloquent Accessing Original

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

                        )

Upvotes: 7

Views: 17073

Answers (2)

Rob Gordijn
Rob Gordijn

Reputation: 6511

When retrieving the original value of an Eloquent model attribute, you can use getOriginal($key)

Reference:

Upvotes: 16

kamlesh.bar
kamlesh.bar

Reputation: 1804

For laravel 4.2 and on

$entries->toArray()

Will provide model attributes only.

Upvotes: 0

Related Questions