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
merged 1 commit into from
Jun 8, 2019

Conversation

imliam
Copy link
Contributor

@imliam imliam 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
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

  • 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants