laravelista / comments

Native comments for your Laravel application.
MIT License
744 stars 142 forks source link

How can i use Cache to store comments? #111

Closed salimedia closed 4 years ago

salimedia commented 4 years ago

Hi After using this package, How can i use Laravel Cache to store comments? like that:

$comments = Cache::rememberForever("comments", function () {
       return CommentResource::collection(Comment::all()->load('user','post'));
});

because in blade we use just this code: @comments(['model' => $post,'approved' => true])

Thank you very much

mabasic commented 4 years ago

Comments for the model are grabbed from model comments() relationship. You could on your controller method where you obtain the model, cache $post->comments for some reason. Don't know what is the use case for this, but it should be doable.