My Controller Considers That My Store Id Is The Products Id
My controlller can't read that the 'sample' is a store and not a product. I have this Route on my web.php
Route::get('{store}/products/{products}/edit', [
'as' => 'store.products.edit',
'uses' => '[email protected]',
function($store) {
$store = App\Models\Store::where('slug', $store)->firstOrFail();
}
]);
and here is my [email protected]
public function edit($id)
{
$product = Product::findOrFail($id);
return view('view here', compact('product'));
}
when I run the url: http://127.0.0.1:8000/sample/products/022fe902-7f4d-4db1-b562-04a7eb9f5a68/edit
where sample is the {store} and 022fe902-7f4d-4db1-b562-04a7eb9f5a68 is the {product}
I get this error:
No query results for model [App\Models\Product] sample
in my query:
select * from
products
whereproducts
.uuid
= 'sample' limit 1
Answer
If you have 2 parameters, you should have them both in your controller in valid order, so you should have:
public function edit($store, $id)
{
$product = Product::findOrFail($id);
return view('view here', compact('product'));
}
Also probably you don't need here:
function($store) {
$store = App\Models\Store::where('slug', $store)->firstOrFail();
}
for anything, but maybe in your controller you should do something like this:
$store = App\Models\Store::where('slug', $store)->firstOrFail();
$product = $store->products()->findOrFail($id);
Assuming you have product in this store and you would like to make sure that someone won't edit product that is assigned to different store.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?