-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Volt:route() middleware not working with "can" #104
Comments
Upon digging into internals it seems route model binding isn't working. I've tracked it down to here: Which returns an empty parameter list when using Volt, and a filled parameter list otherwise. I can't seem to get any further debugging this, sorry. |
This is an issue you need to report on the main Livewire repository (https://github.com/livewire/livewire), as it is not working for regular full page components in Livewire either:
|
Full page Livewire components work if the i.e.
However, it still does not work for Volt. A passing test for the Livewire full page component, as well as the failing Volt test has been added to the test repo here: The relevant discussion on the Livewire repo can be found here: livewire/livewire#8445 Can this issue be re-opened? |
Possibly related: Route model binding also isn't working on Volt components written in a functional way. The following would output "Post View 1", or whatever the
Route model binding does work in Folio if written exactly the same way though. I've added the page to the test repo here: https://github.com/boptom/volt-route-middleware/blob/main/resources/views/livewire/volt-functional-post.blade.php |
In case anyone finds this through Google; I ran into the same issue, but also found an acceptable resolution. I'm using Volt functional components. As previously mentioned Volt does not support implicit route model binding, preventing the model policy from triggering (since the routing system does not have a model to work with). Setting the route model explicitly will fix this issue: class AppServiceProvider
{
public function boot(): void
{
Route::model('post', App\Models\Post::class);
}
} Route::middleware('can:view,post')->group(function () {
Volt::get('posts/{post}', 'pages.posts.index')->name('posts.index'); // previously 403, works as intended with explicit route model binding
}); Don't forget to set up your policy. |
Volt Version
1.0
Laravel Version
11.7
PHP Version
8.3.6
Database Driver & Version
sqlite
Description
Using
'can:view,post'
in middleware inVolt
route always returns 403.e.g.
A minimal Laravel app to show this can be found here: https://github.com/boptom/volt-route-middleware
A test that fails is: https://github.com/boptom/volt-route-middleware/blob/main/tests/Feature/PostTest.php
The app has 2 routes. The alternate route works, showing the policy is correct. The 2 routes can be found in
web.php
here: https://github.com/boptom/volt-route-middleware/blob/main/routes/web.php#L19Steps To Reproduce
In terminal:
The output shows one test passing, and one failing.
The text was updated successfully, but these errors were encountered: