Laravel 5.3 route Post不工作

时间:2016-11-19 19:02:40

标签: php laravel-5.3

您好我最近搬到了Laravel 5.3,我有这个问题适用于5.2

我有简单的表单,我想在用户提交时重定向到索引:

 <form method="post" action="{{ route('create') }}">
         <div class="input-group">
            <label for="movie">Title Of Movie</label>
            <input type="text" name="movie" id="movie" placeholder="Title Of Movie">
         </div>
          <div class="input-group">
             <label for="author">Your Name</label>
             <input type="text" name="author" id="author" placeholder="Your Name">
          </div>
          <div class="input-group">
             <label for="email">Your Email</label>
             <input type="email" name="email" id="email" placeholder="Your Email">
          </div>
          <div class="input-group">
             <label for="quote">Your Quote</label>
             <textarea name="quote" rows="5" id="quote" placeholder="Your Quote"></textarea>
          </div>
          <button type="submit" class="btn">Submit Quote</button>
          <input type="hidden" name="_token" value="{{Session::token()}}">
       </form>

现在这是我的路线/ web.php:

Route::get('/',[
  'uses' => 'QuoteController@getIndex',
  'as'   => 'index'
]);

Route::post('/new',[
   'uses' => 'QuoteController@postQuote',
   'as' => 'create'

]);

这也是我的Quotecontroller:

<?php

namespace App\Http\Controllers;

use App\Author;
use App\Quote;
use Illuminate\Http\Request;

class QuoteController extends Controller
{
  public function getIndex(){
      return view('index');
  }

  public function postQuote(Request $request){

      $authorText = ucfirst($request['author']);
      $quoteText = $request['quote'] ;

      $author = Author::where('name', $authorText)->first();
      if(!$author){
        $author = new Author();
        $author->name = $authorText;
        $author->save();
      }
      $quote = new Quote();
      $quote->quote = $quoteText;
      $author->quotes()->save($quote);


     return redirect()->route('index')->with([
       'success' => 'Quote Saved!'
     ]);
  }

}

我得到的错误是我提交时:

RouteCollection.php第161行中的NotFoundHttpException:

我真的不明白这个问题请帮忙

2 个答案:

答案 0 :(得分:0)

当您延长Controller时,您必须使用App\Http\Controllers\Controller并且不要忘记在表单中同时使用{{ csrf_field() }}

答案 1 :(得分:0)

嘿伙计们,我发现了这个问题,那真的很有趣 在我告诉你什么是错的之前我应该​​告诉你我在Git-hub的文件夹上有这个项目所以当我做更改时我可以添加评论但问题实际上是我命名我的文件夹测试和大写的命名文件夹是有问题的,所以当我将其更改为测试时,它的工作原理 谢谢你的回答