Каждый раз, когда я создаю новый объект, Eloquents сохраняет его и создает еще одну пустую строку.Что может быть причиной этого?Я уже проверил свою модель, контроллер и миграцию, но не могу понять.
Моя модель со всеми перечисленными полями, если необходимо:
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>
Веб:
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::any('/candidates/index','CandidatesController@index');
Route::get('/candidates/apply','CandidatesController@create');
Route::post('/candidates/','CandidatesController@store');
Route::get('/candidates/add','CandidatesController@add');
Route::get('/candidates/edit/{id}', 'CandidatesController@edit');
Route::post('/candidates/edit/{id}', 'CandidatesController@update');
Route::get('/candidates/view/{id}','CandidatesController@view');
Route::get('/candidates/followup','CandidatesController@showFollowUp');
Route::delete('/candidates/delete/{id}', 'CandidatesController@destroy');
Route::get('/excel/export', 'CandidatesController@excelExport');
Route::get('/session/prepare/excel', 'CandidatesController@sessionPrepareExcel');
Route::any('/candidates/prepemail','CandidatesController@prepEmail');
Route::post('/candidates/prepemail','CandidatesController@sendEmail');