I am storing some strings in my database, and I want to be able to get model attributes using them.
Basically, I can call a users booking like this
$user->bookings->date
in my controller and it works, and i'm storing a string in my database like this
'user->bookings->date'
How can I use this string from the database to get the attribute? I'm hoping to be able to do something like
$user = User::findOrFail(1);
$string = 'user->bookings->date'; //This is fetched from the db normally
$booking_date = ${$string}; //Instead of writing $user->bookings->date
Is this possible?
->needs to be outside of{}to work properly. i.e. something like${$string1}->{$string2}->{$string3};would work, but I'm not sure how to construct that dynamically.