oddvalue / laravel-drafts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Middleware not working with route binding

gtrinkwon opened this issue · comments

Please excuse me if this is a misunderstanding on my part - I've tried applying the middleware in a few different ways, but am having some issues getting it to work successfully with route binding with models.

For example (imagine item ID 123 is a draft):

Route::withDrafts(function (): void {
    Route::get('/item/{item}', function() {
        dd(Item::find(123));
    });
});

This works fine. However, something along the lines of:

Route::withDrafts(function (): void {
    Route::get('/item/{item}', ItemController::class, 'edit');
});

...

class ItemController {
    public function edit(Item $item) 
    {
         dd($item);
    }
}

results in a 404. Setting the is_published field to 1 on the item in question allows the page to load, so the route works, it just isn't obeying the middleware and including drafts when binding the item model.

Looks to have been a middleware priority issue. Fixed in latest version.