Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Suggest resolution when no relationship value is returned #28762

merged 1 commit into from Jun 8, 2019


None yet
3 participants
Copy link

commented Jun 8, 2019

By far one of the most common issues I've seen people new to Laravel ask for help with is when they forget the return keyword when defining relationships, to the point where there are nearly 3000 results on Google when you search for the exception.

I guess it comes from the fact builder methods don't have to return a value, and they're often talked about alongside relationships.

All this PR does is put a bit more information and a suggestion in the exception's text to point them in the right direction.

@taylorotwell taylorotwell merged commit 31eee29 into laravel:5.8 Jun 8, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
continuous-integration/travis-ci/pr The Travis CI build passed
@@ -413,6 +413,12 @@ protected function getRelationshipFromMethod($method)
$relation = $this->$method();
if (! $relation instanceof Relation) {
if (is_null($relation)) {
throw new LogicException(sprintf(
'%s::%s must return a relationship instance, but "null" was returned. Was the "return" keyword used?', static::class, $method

This comment has been minimized.

Copy link

mfn Jun 8, 2019



  • Was the "return" keyword used?
  • Is the "return" keyword missing?

@GrahamCampbell GrahamCampbell changed the title Suggest resolution when no relationship value is returned [5.8] Suggest resolution when no relationship value is returned Jun 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.