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

[9.x] Ignore whitespaces/newlines when finding relations in model:show command #45608

Merged

Conversation

binotaliu
Copy link
Contributor

@binotaliu binotaliu commented Jan 11, 2023

The show:model relies on reading methods' source code to finding relations. It's done by finding if the pattern \$this->{$possibleRelationMethod}( appears in the method.
In most situation, it would work:

public function user()
{
    return $this->belongsTo(User::class);
}

But if there are whitespaces/newlines after $this, the command would failed to detect:

public function user()
{
    return $this
        ->belongsTo(User::class)
        ->withDefault([
            'name' => 'Guest Author',
        ]);
}

1

This PR fixes this issue by trimming each line of the relation method's source code, so the pattern \$this->{$possibleRelationMethod}( can be correctly detected.

public function user(){return $this->belongsTo(User::class)->withDefault(['name' => 'Guest Author',]);}

Footnotes

  1. Example code from Laravel Documentation

@taylorotwell taylorotwell merged commit 32666a5 into laravel:9.x Jan 11, 2023
@binotaliu binotaliu deleted the bugfix/show-model-ignore-whitespaces branch January 11, 2023 15:33
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.

2 participants