Ad
Route Not Hitting Controller
When I try to create a view for a product, the URL gets built correctly.
http://localhost:8000/product/my-slug
However, I get a 404 page not found and I have no idea why. It's like the controller is not getting called.
Initiation
<a target="_blank" rel="nofollow noreferrer" href="{{ route('product.view', $product->slug) }}">
Route
Route::get('/product/{$slug}', '[email protected]')->name('product.view');
Controller
public function view($slug)
{
$product = Product::find($slug);
return view('products.view', compact('product'));
}
View
<h1>{{ $product->name }}</h1>
EDIT
web.php
Route::get('/', '[email protected]')->name('product.index');
Route::get('/products/create', '[email protected]')->name('product.create');
Route::post('/products', '[email protected]')->name('product.store');
Route::get('/product/{$slug}', '[email protected]')->name('product.view');
/*Route::get('/users', 'UsersController');*/
Route::get('/contact', '[email protected]');
Route::get('/about', '[email protected]');
Ad
Answer
Try changing
Route::get('/product/{$slug}', '[email protected]')->name('product.view');
to
Route::get('/product/{slug}', '[email protected]')->name('product.view');
Ref: Laravel Routing
Ad
source: stackoverflow.com
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 - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad