A general tip if a route can't be found is to run the php artisan laravel:route command and look for your routes.
The first look at your code is that it should exist.
Hi Tobias,
First of all thanks for your answer.
I had reviewed routes with this command and they doesn´t appear, that is the problem. But, how can I add the Route::resource code to have an existing resource routes?
Can you try php artisan route:clear
it can be that you have the routes cached (with php artisan route:cache
) then the routes will not be loaded from the routes file but from the cache.
Hi again Tobias,
I have already executed route:clear command and the problem still happens. :S
Sure,
| Domain | Method | URI | Name | Action | Middleware |
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
go to your PostController and inside index() method if you have created controller with resource u can see index() method there and there you return view('index'); i hope it will work. else you have to create route::get('/',Controller_Name@index) and then inside index you have to put the return view('/index')
That is my index method code. I had wrote it before the realize problem:
public function index()
{
$products = Product::latest()->paginate(5);
return view('products.index', compact('products'))
->with('i',(request()->input('page', 1)-1)*5);
}
I have created Route::resource, so it shouldn´t be necessary to create the routes using Route::get code.
Solved, I feel a little bit stupid...
I wrote this code:
Route::get('/', function () {
return view('welcome');
Route::resource('products', 'ProductController');
});
Instead of:
Route::get('/', function () {
return view('welcome');
});
Route::resource('products', 'ProductController');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community