我的路线:
Route::get('/', array('as' => 'home', 'uses'=> 'QuestionsController@index') );
Route::get('register', array('as' => 'register', 'uses'=> 'UsersController@getnew'));
Route::post('register', array('uses'=> 'UsersController@create'));
控制器:
public function create()
{
$validation = User::validate(Input::all());
if ($validation->passes()) {
User::create([
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'))
]);
//dd('post created');
return Redirect::to('home')->with('message', 'Thanks for registering');
} else {
return Redirect::to('register')->withErrors($validation)->withInput();
}
}
new.blade.php
:
@extends('layouts.default')
@section('content')
<h1>Register</h1>
@if($errors->has())
<p>The following errors have occurred:</p>
<ul id="form-errors">
{{ $errors->first('username', '<li>:message</li>') }}
{{ $errors->first('password', '<li>:message</li>') }}
{{ $errors->first('password_confirmation', '<li>:message</li>') }}
</ul>
@endif
{{ Form::open(array('url'=>'register', 'method'=>'POST')) }}
{{ Form::token() }}
<p>
{{ Form::label('username', 'Username') }}<br />
{{ Form::text('username', Input::old('username')) }}
</p>
<p>
{{ Form::label('password', 'Password') }}<br />
{{ Form::password('password') }}
</p>
<p>
{{ Form::label('password_confirmation', 'Confirm Password') }}<br />
{{ Form::password('password_confirmation') }}
</p>
<p>{{ Form::submit('Register') }}</p>
{{ Form::close() }}
@stop
当我提交表单时,请检查前往目标表的dd('postcreated')
数据,但是当重定向到主路由时,我会收到以下错误。
[2015-03-22 08:51:33] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php:5747
Stack trace:
#0 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(5069): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#1 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(5057): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(5049): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#3 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(715): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#4 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(696): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#5 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(7821): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#6 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(8428): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#7 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(8375): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#8 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(11040): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#9 E:\Web\xampp\htdocs\makeitsnappy\bootstrap\compiled.php(657): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#10 E:\Web\xampp\htdocs\makeitsnappy\public\index.php(49): Illuminate\Foundation\Application->run()
#11 {main} [] []
当我检查寄存器路线时,一切正常。我的家乡路线有什么问题?
答案 0 :(得分:0)
您应该使用Redirect::route()
(重定向到指定路线),
而不是使用期望重定向到URL的Redirect::to()
。您的测试环境中不存在导致404未找到异常的home
。