Laravel 4.2不会将数据保存到数据库中

时间:2014-06-10 02:54:05

标签: php authentication laravel-4 eloquent

我有一个问题,我不知道我搞砸了哪里但是Laravel没有将数据保存到数据库中,也没有显示任何错误。这是我的代码:

user.php的

    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';

protected $fillable = array('first_name', 'last_name', 'username', 'email', 'password', 'password_temp', 'code', 'active');

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

}

routes.php文件

    Route::get('/',  array(
           'as' => 'home',
           'uses' => 'PagesController@home'
        ));
    //Unauthenticated group
    Route::group(array('before'=>'guest' ), function(){

//CSRF authentication
        Route::group(array('before' => 'csrf'), function(){
       //create account (POST)
         Route::post('/account/create', array(
        'as' => 'account-create',
        'uses' => 'AccountController@postCreate'
    ));
});

//create account GET
Route::get('/account/create', array(
    'as' => 'account-create',
    'uses' => 'AccountController@getCreate'
));
});

Account.php //这是我用来创建帐户的控制器

    class AccountController  extends  BaseController{

     public function getCreate(){
       return View::make('account.create');

    }
     public function postCreate(){

    $validator = Validator::make(Input::all(),

        array(
            'first_name' => 'required',
            'last_name' => 'required',
            'username' => 'required|max:20|min:3|unique:users',
            'email' => 'required|max:50|email|unique:users',
            'password' => 'required|min:6',
            'passsword-repeat' => 'required|same:password'

            )
        );

    if($validator->passes()){
        //activation code
        $code = str_random(60);

        $user = new User;
        //create an account
        $user->first_name = Input::get('first_name');
        $user->last_name = Input::get('last_name');
        $user->username = Input::get('username');
        $user->email = Input::get('email');
        $user->password = Hash::make(Input::get('password'));
        $user->code = $code;
        $user->active = 0;

        $user->save();

            //send email of activation

            return Redirect::to('home')
                   ->with('global', 'Your account has been created! We have sent an email to activate your account');

    }else{
        return Redirect::to('account/create')
               ->withErrors($validator)
               ->withInput();
        }

      }
    } 

以下是我使用的视图: 的 Create.blade.php

           @extends('master')

           @section('content')
           <div class="panel panel-default">
            <div class="panel-heading">Please Register</div>
              <div class="panel-body">
                <div class="col-md-4 col-md-offset-4">
              {{ Form::open(array('route' => 'account-create', 'class' =>  'form-horizontal', 'method' => 'post'))}}
                <fieldset>
                <div class="control-group">
                 {{ Form::label('first_name', 'First name', array('class' => 'control-label') )}}
                   <div class="controls">
                    {{ Form::text('first_name', Input::old('first_name'), array('class' => 'form-control input-medium', 'placeholder' => 'Enter Your First Name') )}}
                      <p class="error">{{ $errors->first('first_name')}}</p>
                      </div>
                   </div>     
                  <div class="control-group">
                    {{ Form::label('last_name', 'Last name', array('class' => 'control-label') )}}
                    <div class="controls">
                     {{ Form::text('last_name', Input::old('last_name'), array('class' => 'form-control input-medium', 'placeholder' => 'Enter Your Last Name') )}}
                     <p class="error">{{ $errors->first('last_name')}}</p>
                    </div>
                   </div>    
                   <div class="control-group">
                   {{ Form::label('username',  'Username', array('class' => 'control-label') )}}
                   <div class="controls">
                   {{ Form::text('username',Input::old('username'), array('class' => 'form-control input-medium', 'placeholder' => 'Enter Your Username') )}}
                    <p class="error">{{ $errors->first('username')}}</p>
                    </div>
                    </div>   
                    <div class="control-group">
                    {{ Form::label('email',  'Email', array('class' => 'control-label') )}}
                    <div class="controls">
                    {{ Form::text('email', Input::old('email') , array('class' => 'form-control input-medium', 'placeholder' => 'Enter Your Email') )}}
                     <p class="error">{{ $errors->first('email')}}</p>
                    </div>
                    </div>

                    <!-- Password input-->

                    <div class="control-group">
                    {{ Form::label('password',  'Password', array('class' => 'control-label') )}}
                    <div class="controls">
                     {{ Form::password('password', array('class' => 'form-control')) }}
                     <p class="error">{{ $errors->first('password')}}</p>
                    </div>
                    </div> 
                    <div class="control-group">
                    {{ Form::label('password-repeat', 'Re-Enter Password', array('class' => 'control-label') )}}
                    <div class="controls">
                    {{ Form::password('password-repeat', array('class' => 'form-control')) }}
                     <p class="error">{{ $errors->first('password-repeat')}}</p>
                    </div>
                    </div>   


                <!-- Button -->
                <div class="control-group">

                 <div class="controls">
                  {{Form::submit('Sign Up', ['class' => 'btn btn-large btn-primary', 'id'=> 'signup'])}}

                  </div>
                </div>

         </fieldset>

        {{ Form::close() }}
        </div>
      </div>
   </div>

@stop

验证很好,但每当我想创建一个用户并将数据保存到数据库时,没有任何事情发生,它返回到我尝试保存的数据的同一登录页面,没有任何错误消息。如果你能发现我的错误,请帮帮我

0 个答案:

没有答案