user

Yasen Sayed

23 Feb 2022

How to get original attribute value in Laravel?

Laravel

Hello guys, Please anyone can help me to get the original attribute in Laravel?

Comments

Mahmoud Santos

23 Feb 2022

Best Answer

best answer

You can try this I hope this will help you.

Model::first()->getOriginal()

Also, you can do this if you like to get attributes only.

Model::first()->getAttributes();

 

Replies

Yasen Sayed

23 Feb 2022

Oh, How interesting it's worked successfully.

 

Thanks a lot 

Shilpa

26 Feb 2022

github

If you are using laravel v5.0+ then this will help you for sure.

$originalArr= $model->getOriginal('arg1');

getOriginal() method is intended to bring original value of the attribute, which was loaded from the db. Also note that, If you change the value it will not work!

In such cases, For good practices, you may need

$originalArr= $model->setSomeArg('arg2');

This will preserve value in the $originalArr array.

© 2024 Copyrights reserved for web-brackets.com