Answer the question
In order to leave comments, you need to log in
Is it possible to optimize queries?
Is it possible to somehow optimize requests for the output of a post, comments to it and tags
there is a Post model
class Post extends Model
{
use HasFactory;
protected $table = 'posts';
public function comments()
{
return $this->hasMany(Comment::class);
}
public function tags()
{
return $this->hasMany(Tag::class);
}
}
public function single(int $id){
$post = Post::find($id);
$comments = $post->comments()->latest()->take(20)->get();
$tags = $post->tags()->latest()->take(5)->get();
return view('single', compact(['post','comments','tags']));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question