Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

michaelhany's avatar

eloquent query scopes question

I was wondering what difference does it make to return the query, i've been working with scopes for a some time and yet to find a difference.

public function scopePublished($query)
{
	return $query->where('published', true);
}

vs

public function scopePublished($query)
{
	$query->where('published', true);
}

both seems to work quite the same even with chaining multiple scopes

0 likes
1 reply
jlrdw's avatar

Usually called from controller, you generally need "return".

I have never tried it without return. Also, I'd go with documentation examples no matter.

Please or to participate in this conversation.