duanlian1960 2014-06-10 02:54
浏览 24

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

I have a problem, i don't know where i'm messing up but Laravel does not save data to the database and it does not display any errors. Here is my code:

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 //Here is the Controller that i used to create accounts

    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();
        }

      }
    } 

Here is the view i have used: 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

It validates well but whenever i want to create a user and save data to the database nothing is happening and it returns back to the same login page with the data i tried to save without any error message . please help me if you can spot my mistake

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)