Created
September 27, 2019 06:26
-
-
Save cartoonclouds/acfe6edabb06c16c2152ff1cdaddd8f8 to your computer and use it in GitHub Desktop.
Laravel - WithAndWhereHas Scope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function scopeWithAndWhereHas($query, $relation, $constraint){ | |
return $query->whereHas($relation, $constraint) | |
->with([$relation => $constraint]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment