sustained
10 months ago

No queries being exected with route-model binding?!

Posted 10 months ago by sustained

Why is implicit route-model binding not working for me? I have this route in api.php:

Route::get('guild/{discord_id}', '[email protected]');

And this model:

class Guild extends Model
{
    public function getRouteKeyName()
    {
        return 'discord_id';
    }
}

And this controller:

class GuildController extends Controller
{
    public function show(Request $request, Guild $guild)
    {
        return $guild;
    }
}

I have removed use statements etc. for clarity.

If I setup the binding explicitly in RouteServiceProvider.php then it works?

    public function boot()
    {
        parent::boot();

        Route::bind('guild', function ($value) {
            return Guild::where('discord_id', '=', $value)->first();
        });
    }

If I check Telescope, no queries are even being executed?

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