Implicit model binding in routes returns multiple values when using "with" in controller.

Posted 1 year ago by dmarman

This will work as it should. It returns the object that corresponds to the id in the url:

public function show(Listing $listing)
    {
        return $listing;
    }

But this will return a collection of objects:

public function show(Listing $listing)
    {
        return $listing->with('webhook', 'emailNotification')->withCount('emails', 'visits')->get();
    }

the with and withCount will trigger this unwanted behaviour. Am I doing something wrong?

Please sign in or create an account to participate in this conversation.