Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

php - Laravel: Using an instance created in one function within another?

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?

use AppModelsUserProduct;

public function setData($data) {
    // other logic
    UserProduct::create([
       'id' => $data->id
    ]);

}

public function logInfo() {
   
    $myVar = UserProduct::latest()->first();
 
    //use myVar

}
question from:https://stackoverflow.com/questions/66057725/laravel-using-an-instance-created-in-one-function-within-another

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...