尝试保存在DB上时,Laravel表单数据重定向到错误

时间:2014-10-08 12:02:32

标签: laravel laravel-4

我已经使用Laravel创建了注册表单,表单运行良好,Validations也运行良好但是没有验证错误,当我尝试保存数据时,它重定向到“哎呀,看起来出了问题。” / strong>有人可以帮我找到这个错误。谢谢。

表格:

{{ Form::open(array('url'=>"create-account")) }}
<p>
    {{ Form::text('user_name', '', array('placeholder'=>"User Name")) }}
    @if($errors->has('user_name'))
        <label> {{  $errors->first('user_name') }} </label>
    @endif
</p> 
<p>
    {{ Form::text('user_email', '', array('placeholder'=>"User Email")) }}
    @if($errors->has('user_email'))
        {{ $errors->first('user_email') }}
    @endif
</p>
<p>
    {{ Form::password('user_password', array('placeholder'=>"User Password")) }}
    @if($errors->has('user_password'))
        {{ $errors->first('user_password') }}
    @endif
</p> 
<p>{{ Form::submit('Register') }}</p>
{{ Form::close() }}

并且Controller有以下代码:

class StaffController extends BaseController {

    public function getAccount() {
        return View::make('staff.account');
    }

    public function postAccount() {
        $input = Input::all();
        $rules = array(
            'user_name' => 'required|min:3|max:20|unique:users',
            'user_email' => 'required|email|max:50|unique:users',
            'user_password' => 'required|min:5'
        );
        $validate = Validator::make($input, $rules);

        if ($validate->fails()) {
            return Redirect::to('create-account')
                            ->withErrors($validate);
        } else {
                $user = new User();
                $user->user_name = $input['user_name'];
                $user->user_email = $input['user_email'];
                $user->user_password = Hash::make($input['user_password']);
                $user->save();
                return Redirect::to('login')
                        ->with('global', 'Your account has been created, please login'); 
        }
    }

}

型号:

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    //protected $hidden = array('password', 'remember_token');
        protected $hidden = array('user_password');

}

数据库表包含字段:

表名:用户 领域: user_id int(11)
user_name varchar(20)
user_email varchar(50)
user_password varchar(60)
状态

路线:

Route::get('/','HomeController@getIndex');
Route::get('login','HomeController@getIndex');
Route::post('login','HomeController@postLogin');
Route::get('create-account', 'StaffController@getAccount');
Route::post('create-account', 'StaffController@postAccount');

0 个答案:

没有答案