0

I have a database Namely "Marriages" and an user can insert his Marital information and that inserted values stored in this database.Here i have several fields including present address.

But in present address the posted data is not inserting though other posted data is inserting in the associated field,after a lots of research i can not figure out the problem.Here is my files.

Migration :

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!');
    }

   }

}

Template(Only the Present Address Field):

<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>

Model:

<?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;

}

i am really confused why only the present address data is not inserting.If you see any issues in my code,please let me know.

7
  • Not sure about the issue but why double code for same thing, you may use directly 'present_address' => Input::get('present_address') instead. Commented Dec 31, 2014 at 9:04
  • Also make sure that you have present_address in the form. Commented Dec 31, 2014 at 9:05
  • I have present address field in my form for sure. @The Alpha Commented Dec 31, 2014 at 9:08
  • And I am also making sure that each time i am passing present address @The Alpha Commented Dec 31, 2014 at 9:09
  • 2
    @Rego did you add present_address to your model $fillable array? Can you share model code? Commented Dec 31, 2014 at 9:12

1 Answer 1

1

Whenever insert, update in laravel you have add $fillable array in laravel eloquent model check this for more details http://laravel.com/docs/4.2/eloquent#mass-assignment

Sign up to request clarification or add additional context in comments.

1 Comment

i have added my Model file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.