I'm trying to setup my laravel project but I cant seem to get routing to work. This is my routes/web.php: Route::post('test','UserController@test'); Route::resource('/','UserController');
Now my /
works. The functions in it work, but Laravel says my test
does not exist. I get a 404 error
.
In my /
index I have a form like this:
<form method="POST" action="test">
It goes from laravel/public/
to laravel/public/test
. But apparently laravel/public/test
gives back a 404 error. I tried to fix it with: Route::post('/test','UserController');
but it gives the same error. The only 2 differencex with the documentation that I see is that I'm working from /
which shouldnt make a difference(?) and that I'm not working directly from localhost/
but with some maps where I stored my project. Which shouldnt make a difference either. What am I doing wrong here?
EDIT:
My controller:
class UserController extends Controller{
public function index()
{
return view('testindex');
}
public function test(){
return 'test';
}
}
You should then fix it by one of the following:
public function postTest(){
return 'test';
}
or in routes/web.php
Route::post('test','UserController@test');
You're using wrong web server settings. You need to point web server to the public
directory inside Laravel root and use correct settings.
For Apache:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
For nginx:
root /path_to_laravel_project/public;