I have a User controller where set Data is run at a certain point and UserProduct's create method is used to create a UserProduct. I want to use the UserProduct in a different function. Would the best way to do so just query the latest record of UserProduct and set it to a variable?
User
UserProduct
use AppModelsUserProduct; public function setData($data) { // other logic UserProduct::create([ 'id' => $data->id ]); } public function logInfo() { $myVar = UserProduct::latest()->first(); //use myVar }
2.1m questions
2.1m answers
60 comments
57.0k users