I have PHP 8, Laravel 9 with Inertia (Vue 3). I have a resource controller inside a grouped route. See the code below:
Route::group([
'prefix' => '{locale?}',
'where' => ['locale' => '[a-zA-Z]{2}'],
'middleware' => 'set-locale',
], function () {
Route::resource('/sliders', SliderManagement::class);
});
I created a link in a vue page to visit sliders.show. Check the vue code below:
<a v-for="slider in sliders" :key="slider.id" :href="route('sliders.show', {slider: slider.id, locale: locale})">Go to slider {{ slider.id }}</a>
When I visit the link, I am getting the following error:
App\Http\Controllers\Admin\SliderManagement::show(): Argument #1 ($slider) must be of type App\Models\Slider, string given, called in /home/atif/Desktop/Freelancing/Sebastian Projects/98goal.com/98goal.com/vendor/laravel/framework/src/Illuminate/Routing/Controller.php on line 54
The code related to the show method is as follows:
public function show(Slider $slider) {
return Inertia::render('Admin/Slider/Edit', ['slider' => $slider]);
}
Can you check the request that is executed from vue?
It looks like you route will be domain.tld/{locale}/sliders/{slider}
where slider should be an integer that will be transformed to the Slider model but your error say it is a string.
I have checked the route.
Route is http://127.0.0.1:8000/en/sliders/2
Slider with id=2 also exists in the database
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community