您好我最近搬到了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:
我真的不明白这个问题请帮忙
答案 0 :(得分:0)
当您延长Controller
时,您必须使用App\Http\Controllers\Controller
并且不要忘记在表单中同时使用{{ csrf_field() }}
。
答案 1 :(得分:0)