0

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';
   }
}
Loko
  • 6,539
  • 14
  • 50
  • 78

2 Answers2

0

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');
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
0

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;
Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279