Answer the question
In order to leave comments, you need to log in
How to cache model with attributes in laravel?
Hey!
I have a user model with an email accessor that just needs to pull data from a remote server.
More or less like this:
public function getEmailAttribute(){
$curl = new Curl;
$responseJson = $curl->post('https://mydb.remote/api/user.json',array(
'user_id'=>$this->id
));
$response = json_decode($responseJson);
return $response->email;
}
$value = Cache::remember('users', $minutes, function () {
return User::find($id);
});
Answer the question
In order to leave comments, you need to log in
you just need to pull data from a remote server
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question