doujiang6944 2017-03-01 09:20
浏览 47

使用索引文件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::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';
   }
}
  • 写回答

2条回答 默认 最新

  • dongzi0602 2017-03-01 09:25
    关注

    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');
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改