Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

php artisan route:cache doesn't work with route model bindings

$this->bind('project', function ($project)
  {
    try
    {
      return Project::whereKey($project)->firstOrFail();
    }
    catch(ModelNotFoundException $e)
    {
      throw new NotFoundHttpException;
    }

  });

How can i cache this binding?

UPD. I replace a anonimous function to string RouteBindings@project, but bindings still not caching with php artisan route:cache

UPD2 Problem solved with placing bindings to RouteServiceProvider::boot

Last updated 2 years ago.
0

Thanks! Was looking for this. Update 2 fixed it for me! :-)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Londeren londeren Joined 11 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.