Hello, in Post model i use this method to get the path of current post
Post Model :
public function path () { return url ( 'posts/'.{$this->id} ); }
when i make loop throw posts like
foreach ( $posts as $post) {
$post->path
}
is $post->path here will make another query to the database or will take the id from current $post of loop
of course i'dont want to make another query because i already has it in $post of the loop . Thanks
Use something like Laravel Debugbar to check your queries. Its easy to get into an n+1 error. As we don't see the rest of your code, it is assumed that all Post models are fully hydrated.