我有一个数据库,名为“婚姻”,用户可以插入他的婚姻信息以及存储在此数据库中的插入值。这里有几个字段,包括当前地址。
但是在当前地址中,发布的数据没有插入,但其他发布的数据正在相关字段中插入,经过大量研究我无法弄清楚问题。这是我的文件。< / p>
迁移:
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();
});
}
控制器:
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;
}
我真的很困惑为什么只有当前地址数据没有插入。如果您在我的代码中发现任何问题,请告诉我。
答案 0 :(得分:1)
每当插入,在laravel中更新时,您在laravel eloquent模型中添加$fillable
数组,请查看此更多详细信息http://laravel.com/docs/4.2/eloquent#mass-assignment