gpt4 book ai didi

php - laravel4 数据未插入单个字段

转载 作者:行者123 更新时间:2023-11-29 12:29:53 26 4
gpt4 key购买 nike

我有一个名为“婚姻”的数据库,用户可以插入他的婚姻信息以及存储在该数据库中的插入值。这里我有几个字段,包括当前地址

但是在当前地址中,尽管其他已发布数据正在关联字段中插入,但发布的数据并未插入,经过大量研究,我无法找出问题所在。这是我的文件。

迁移:

Schema::create('marriages', function(Blueprint $table)
{
$table->increments('id');
$table->boolean('approved')->default(false);
$table->string('candidate_name',255)->unique();
$table->string('email',255)->unique();
$table->string('father_name',60);
$table->string('mother_name',60);
$table->date('date_of_birth');
$table->string('sex',60);
$table->string('location',255);
$table->string('blood_group',20);
$table->string('religion',60);
$table->string('present_address',255);
$table->string('permanent_address',60);
$table->string('height',100)->nullable();
$table->string('complexion',100);
$table->string('nationality',100);
$table->string('educational_qualification',255);
$table->string('occupation',255);
$table->integer('phone_number');
$table->integer('number_of_bro_sis');
$table->string('image',255);
$table->timestamps();
});
}

Controller :

public function postMarriageInfo()
{
$validator = Validator::make(Input::all(),array
(
'candidate_name' => 'required',
'father_name'=> 'required',
'mother_name' => 'required',
'date_of_birth' => 'required',
'present_address' => 'required',
'permanent_address'=> 'required',
'educational_qualification' => 'required',
'height' => 'required',
'location' => 'required',
'complexion' => 'required',
'nationality' => 'required',
'occupation' => 'required',
'number_of_bro_sis' => 'required',
'religion' => 'required',
'sex' => 'required',
'blood_group' => 'required',
'email' => 'required',
'phone_number' => 'required',
'image' => 'required',
));

if($validator->fails()){
return Redirect::route('marriage-form')
->withErrors($validator)
->withInput()
->with('global','There is an error,currently data is not posting!');
}
else
{
//get Matrimonial Information

//Session::flash('it is working');

$file = Input::file('image');
$image_name = $file->getClientOriginalName();

$file_path = $file->move(public_path().'/uploads/marriage_images',$image_name);

$name = Input::get('candidate_name');
$father_name = Input::get('father_name');
$mother_name = Input::get('mother_name');
$date_of_birth = Input::get('date_of_birth');
$present_address = Input::get('present_address');
$permanent_address = Input::get('permanent_address');
$location = Input::get('location');
$educational_qualification = Input::get('educational_qualification');
$height= Input::get('height');
$complexion = Input::get('complexion');
$nationality = Input::get('nationality');
$occupation = Input::get('occupation');
$num_of_bro_sis = Input::get('number_of_bro_sis');
$religion = Input::get('religion');
$sex = Input::get('sex');
$blood_group = Input::get('blood_group');
$email = Input::get('email');
$phone_number = Input::get('phone_number');
//$image = Input::file('image');
//$destinationPath = 'uploads';

// $image_name = $image->getClientOriginalName();
//$image_upload = $image->move($destinationPath,$image_name);


$marriage_info = Marriage::create(array(
'candidate_name' => $name,
'father_name' => $father_name,
'mother_name' => $mother_name,
'date_of_birth' => $date_of_birth,
'present_address' => $present_address,
'permanent_address' => $permanent_address,
'location' => $location,
'educational_qualification' => $educational_qualification,
'height' => $height,
'complexion' => $complexion,
'nationality' => $nationality,
'occupation' => $occupation,
'number_of_bro_sis' => $num_of_bro_sis,
'religion' => $religion,
'sex' => $sex,
'blood_group' => $blood_group,
'email' => $email,
'phone_number' =>$phone_number,
'image' => $image_name
));

if($marriage_info){

return Redirect::route('marriage-form')
->with('global','You have Successfully Registered!');
}

}

}

模板(仅当前地址字段):

<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label">Present Address</label>
<div class="col-sm-8">
<textarea
class="form-control" rows="3" name="present_address"{{(Input::old('present_address')) ? ' value="'.e(Input::old('present_address')).'"' : ''}}>
</textarea>
@if($errors->has('present_address'))
<span style="color:red;">
{{$errors->first('present_address')}}
</span>
@endif
</div>

</div>

型号:

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class Marriage extends Eloquent implements UserInterface, RemindableInterface {



public function getRememberToken()
{
return $this->remember_token;
}

public function setRememberToken($value)
{
$this->remember_token = $value;
}

public function getRememberTokenName()
{
return 'remember_token';
}

protected $fillable=array
( 'candidate_name',
'father_name',
'mother_name',
'date_of_birth',
'present_adddress',
'permanent_address',
'educational_qualification',
'height',
'location',
'complexion',
'nationality',
'occupation',
'number_of_bro_sis',
'religion',
'sex',
'blood_group',
'email',
'phone_number',
'image'
);

protected $table='marriages';


use UserTrait, RemindableTrait;

}

我真的很困惑为什么只有当前地址数据没有插入。如果您在我的代码中发现任何问题,请告诉我。

最佳答案

每当在 Laravel 中插入、更新时,您都会在 Laravel Eloquent 模型中添加 $fillable 数组,请检查此以获取更多详细信息 http://laravel.com/docs/4.2/eloquent#mass-assignment

关于php - laravel4 数据未插入单个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27718660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com