laravel / folio

Page based routing for Laravel.
MIT License
568 stars 46 forks source link

Route model binding connection #123

Closed undjike closed 9 months ago

undjike commented 10 months ago

Folio Version

1.1.3

Laravel Version

10.22.0

PHP Version

8.2.3

Description

It seems like the Folio route model binding resolution happens before middlewares are applied 🤔. Thus, in my case, I had a middleware in charge of changing the current database connection dynamically.

I tried using the default routing system in the same project and things started working as expected. Back to Folio, it's no longer working (resolving the suitable database connection).

Steps To Reproduce

Using Folio, create a middleware that sets the default database connection. Route model binding will still use the default.

undjike commented 10 months ago

@nunomaduro any solution or workaround pls ?

undjike commented 10 months ago

@taylorotwell can you help, please?

nunomaduro commented 10 months ago

In traditional Laravel applications, you are able to define your own middleware priority by placing the SubstituteBindings at the end of your middleware stack. However, in Folio, you are not able to do that, and your own middleware will always run after model route binding.

As workaround, I suggest you to not use model route binding, and use regular route parameters.

Going to let @taylorotwell also give his opinion on this.

taylorotwell commented 9 months ago

Agree - don't think this is possible with Folio at the moment. We always place the web middleware before all other user middleware.

mkhleel commented 5 months ago

in web.php

Route::middleware([
      YOUR_MIDDELWARES,
])->group(function () {
      Folio::route(PATH)
});

I'm using multi-db tenancy and this is working for me, I deleted FolioServiceProvider.php file

undjike commented 1 month ago

in web.php

Route::middleware([
      YOUR_MIDDELWARES,
])->group(function () {
      Folio::route(PATH)
});

I'm using multi-db tenancy and this is working for me, I deleted FolioServiceProvider.php file

Great 👍, thanks. @taylorotwell should we take this one as the suitable way to achieve it? Is there any caution or downside doing it this way?