【问题标题】:How to solve undefined index error in laravel如何解决laravel中未定义的索引错误
【发布时间】:2014-10-07 19:34:53
【问题描述】:

大家好,我是 laravel 的新手,我创建了父母表格,父母填写他的详细信息。所以我的问题是当用户输入所有的填充和提交按钮时给出的错误是未定义的索引:用户名。 这个查询的确切原因是什么我显示我的控制器以及我的视图

控制器

public function parentStepOne(){

    $username = $_REQUEST["username"];    
    $valid_username = Guardian::where('username', '=', $username)->count();

        if($valid_username  == 0){
          $guardian = new Guardian; 
          $guardian->username = $username;
          $guardian->password = Hash::make($_REQUEST["password"]);
          $guardian->save();
          Session::put("guardian",$guardian->id);
          return Redirect::to("/parents/pstep2");
        }

我的看法

<div class="form"> {{ Form::open(array('url' => '/api/v1/parent/parent_step_1', 'class' => "rgform form-horizontal worldoo-form", 'id' => "registrationForm", 'method' => "POST" )) }}
                    <div class="form-group "> {{ Form::label('username', 'Parent’s Username:', array('class' => "control-label")); }}
                      <div class=""> {{ Form::text('username', '', array('class' => "form-control", 'id' => "username"));}} </div>
                      <p>Please confirm your username, your e-mail will be your unique login ID.</p>
                      </div>
                    <div class="form-group"> {{ Form::label('password', 'Please choose a password for yourself:', array('class' => "control-label"));}}
                      <div class=""> {{Form::password('password', array('class' => "form-control", 'id' => "password"));}} </div>
                    </div>
                    <div class="form-group "> {{ Form::label('confirm_password', 'Please re - enter the same password:', array('class' => "control-label"));}}
                      <div class=""> {{Form::password('confirm_password', array('class' => "form-control", 'id' => "confirm_password"));}} </div>
                      <p>Please remember or note your password you will need it to log into worldoo as a parent.</p>
                    </div>
                    <div class="form-group">
                      <div class="text-center"> {{Form::submit('Next', array('class' => "btn btn-primary worldoo-btn"));}} </div>
                    </div>
                    {{ Form::close() }} </div>




}   

【问题讨论】:

  • 尝试在方法顶部执行此dd(Input::all()); 以检查接收到的数据。另外,不要在 Laravel 中使用超全局变量 - 使用 Input 门面或 Illuminate\Http\Request 类。
  • 违反完整性约束:1048 在 save() 附近给出错误
  • 使用dd($_REQUEST); 告诉我你得到了什么?

标签: php laravel-4


【解决方案1】:

试试:$username = Input::get('username');

【讨论】:

  • 违反完整性约束:1048 接近 save() $guardian = new Guardian; $guardian->用户名 = $用户名; $监护人->密码= $密码; $guardian->save();
  • 你做了Hash::make(Input::get('password')); 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-17
  • 2019-11-16
  • 2020-03-01
  • 2011-12-24
  • 2013-02-14
  • 2014-08-20
相关资源
最近更新 更多