Wednesday, March 1, 2017

Routing with index file laravel 5.4

I'm trying to setup my laravel project but I cant seem to get routing to work. This is my routes/web.php:

Route::resource('/','UserController');
Route::post('test','UserController@test');

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';
   }
}




via Loko

Advertisement