Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 存储区插入正确的数据和空行Laravel 5.7_Php_Database_Laravel_Eloquent - Fatal编程技术网

Php 存储区插入正确的数据和空行Laravel 5.7

Php 存储区插入正确的数据和空行Laravel 5.7,php,database,laravel,eloquent,Php,Database,Laravel,Eloquent,每次我创建新对象时,Eloquent都会保存它并生成另一个空行。这是什么原因造成的?我已经检查了我的模型、控制器和迁移,但还没有弄清楚 我的模型,根据需要列出所有字段: protected $fillable = ['first_name','last_name','birth_date','mobile_phone','educational_level','cv','location','email','recommendation]; 控制器,存储方法: public functio

每次我创建新对象时,Eloquent都会保存它并生成另一个空行。这是什么原因造成的?我已经检查了我的模型、控制器和迁移,但还没有弄清楚

我的模型,根据需要列出所有字段:

 protected $fillable =
 ['first_name','last_name','birth_date','mobile_phone','educational_level','cv','location','email','recommendation];
控制器,存储方法:

public function store(Request $request)
{
    $candidate = new Candidate;

    Candidate::create([

    'first_name' => request('first_name'),
    'last_name' => request('last_name'),            
    'email' => request('email'),
    'birth_date' => request('birth_date'),
    'mobile_phone' => request('mobile_phone'),
    'education_level' => request('education_level'),
    'cv' =>  request('cv'),
    'location' => request('location')
    'recommendation' => request('recommendation')
]);

$candidate->save();

    return view('/candidates/index', [
        'candidate' => $candidate
    ]);
}
迁移-由于我没有收到任何错误,因此可以看到正在工作

public function up()
{
    Schema::create('candidates', function (Blueprint $table) {
        $table->increments('id');
        $table->tinyInteger('round_number')->nullable()->default(1);
        $table->string('first_name', 50);
        $table->string('last_name', 50);
        $table->string('email', 50);
        $table->date('birth_date');
        $table->string('mobile_phone', 20);
        $table->text('personal_remarks')->nullable();
        $table->tinyInteger('educational_level')->nullable();
        $table->text('educational_remarks')->nullable();
        $table->tinyInteger('english_reading_level')->nullable();
        $table->tinyInteger('english_writing_level')->nullable();
        $table->tinyInteger('english_conversation_level')->nullable();
        $table->string('cv', 50);
        $table->tinyInteger('cv_grade')->nullable();
        $table->date('cv_grade_date')->nullable();
        $table->text('cv_comment')->nullable();
        $table->date('interview_date')->nullable();
        $table->text('phone_interview_comment')->nullable();
        $table->tinyInteger('phone_interview_grade')->nullable();
        $table->tinyInteger('in_edit')->default(0);
        $table->string('location', 20);
        $table->text('linkendin_profile')->nullable();
        $table->timestamps();

        $table->unsignedInteger('cv_graded_by')->nullable();
        $table->unsignedInteger('phone_interviewer')->nullable();

        $table->foreign('cv_graded_by')->references('id')->on('users');
        $table->foreign('phone_interviewer')->references('id')->on('users');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('candidates');
}
还有,我的观点,以防我遗漏了什么:

     <div class="container">
      <div class="row">
        <div class="col-8">
          <form action="/candidates" method="POST">
              {{ csrf_field()  }}
              <br>
              <div class="form-group">
                <label for="email">Email</label>
                <input name="email" type="email" class="form-control" id="email" placeholder="email" required>
              </div>
          <div class="form-group">
            <label for="first_name">First Name</label>
            <input name="first_name" type="text" class="form-control" id="first_name" required>
          </div>

          <div class="form-group">
            <label for="last_name">Last name</label>
            <input name="last_name" type="text" class="form-control" id="last_name" placeholder="last name" required>
          </div>

           <div class="form-group">
            <label for="location">Location</label>
            <input name="location" type="text" class="form-control" id="location" placeholder="location" required>
          </div>

          <div class="form-group">
            <label for="birth_date">Birth date</label>
            <input name="birth_date" type="" class="form-control" id="birth_date" placeholder="birth date" required>
          </div>

          <div class="form-group">
            <label for="educational_level">Edu level</label>
            <input name="educational_level" type="text" class="form-control" id="educational_level" placeholder="educational_level" required>
          </div>

          <div class="form-group">
            <label for="mobile_phone">Mobile phone</label>
            <input name="mobile_phone" type="text" class="form-control" id="mobile_phone" placeholder="mobile_phone" required>
          </div>


           <div class="form-group">
            <label for="cv">CV</label>
            <input name="cv" type="text" class="form-control" id="cv" placeholder="CV" required>
          </div>

           <div class="form-group">
            <label for="recommendation">Recommendation letter here</label>
            <input name="recommendation" type="text" class="form-control" id="recommendation" placeholder="recommendation">
          </div>

        <button type="submit" class="btn btn-primary">Submit</button>
      </form>
    </div>
  </div>
</div>

这是因为您显式保存了两个候选对象

一个

$candidate = new Candidate;
$candidate->save();
两个

Candidate::create([]);
如果您不知道,这个create方法会将数据保存到数据库中

作为最后一个答案,您的存储功能应该如此简单

public function store(Request $request)
{
    $candidate = Candidate::create([
        'first_name' => request('first_name'),
        'last_name' => request('last_name'),            
        'email' => request('email'),
        'birth_date' => request('birth_date'),
        'mobile_phone' => request('mobile_phone'),
        'education_level' => request('education_level'),
        'cv' =>  request('cv'),
        'location' => request('location')
        'recommendation' => request('recommendation')
    ]);

    return view('/candidates/index', [
        'candidate' => $candidate
    ]);
}

谢谢,成功了。我正在阅读文档,但不知怎么的,我还是错过了像这样的东西。这会向其他用户显示问题已解决。
public function store(Request $request)
{
    $candidate = Candidate::create([
        'first_name' => request('first_name'),
        'last_name' => request('last_name'),            
        'email' => request('email'),
        'birth_date' => request('birth_date'),
        'mobile_phone' => request('mobile_phone'),
        'education_level' => request('education_level'),
        'cv' =>  request('cv'),
        'location' => request('location')
        'recommendation' => request('recommendation')
    ]);

    return view('/candidates/index', [
        'candidate' => $candidate
    ]);
}