Reputation: 3
I have a problem with code using Laravel. I define an attribute in a model to get a list. It takes a lot of time. I use this model in a controller. Follow the code:
protected $appends=["consume_info"];
public function getConsumeInfoAttribute(){
//query a lot of information from mysql
}
I'm wondering if there is an attribute in Controller or Model to avoid a query with mysql in model.
Is there a setting to tell Laravel when to load this appended attribute or not?
Upvotes: 0
Views: 60
Reputation: 3967
Why not just remove the consume_info
from $appends array. You will get the $model->consumer_info
and that too only when you need this.
Upvotes: 1