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] Fix implicitBinding and withTrashed route with child with no SoftDeletes trait #41282

Conversation

stein-j
Copy link
Contributor

@stein-j stein-j commented Mar 1, 2022

This fixes an issue caused when using implicitBinding and withTrashed on a route and where the parent model has the SoftDelete trait and the child doesn't have the SoftDelete trait.

Ex:

class User extends Model
{
    use SoftDeletes;

    public function posts()
    {
        return $this->hasMany(Post::class);
    }

}

class Posts extends Model
{
    //
}

Route::scopeBindings()->get('users/{user}/posts/{post}', /*...*/)->withTrashed();

The following route call /users/1/posts/2 will throw this error Call to undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed().


This PR adds an extra check to verify if the child model instance has the SoftDeletes trait.

@stein-j stein-j changed the title Fix trashed implicitBinding with child with no softdelete Fix implicitBinding and withTrashed route with child with no SoftDeletes trait Mar 1, 2022
@GrahamCampbell GrahamCampbell changed the title Fix implicitBinding and withTrashed route with child with no SoftDeletes trait [9.x] Fix implicitBinding and withTrashed route with child with no SoftDeletes trait Mar 1, 2022
@taylorotwell taylorotwell merged commit b8be411 into laravel:9.x Mar 1, 2022
@stein-j stein-j deleted the fix-trashed-implicitBinding-with-child-with-no-softdelete branch March 30, 2022 13:44
@BrandonSurowiec
Copy link
Contributor

@taylorotwell Can this fix be backported to 8.x? The bug is present there as well.

@driesvints
Copy link
Member

@BrandonSurowiec I think we can. Can you try a PR?

@BrandonSurowiec
Copy link
Contributor

@driesvints Sure. Just won't get to it until the weekend. There are probably a few other PRs submitted to 9.x like the recent Http::retry() fix that could also be backported as a bug fix.

@driesvints
Copy link
Member

@BrandonSurowiec Nothing is urgent : )

BrandonSurowiec pushed a commit to BrandonSurowiec/framework that referenced this pull request Apr 4, 2022
taylorotwell pushed a commit that referenced this pull request Apr 4, 2022
…41814)

(cherry picked from commit b8be411)

Co-authored-by: Jori Stein <44996807+stein-j@users.noreply.github.com>
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.

None yet

4 participants