// qualification.php model
<?php class Qualification extends \Eloquent { protected $fillable = ['jobseeker_id','level_of_education','exam_title', 'institute_name', 'insOther', 'result', 'year_of_passing', 'duration', 'achievement']; protected $table = 'qualifications'; public function jobseeker() { return $this->belongsTo('Jobseeker'); } } // this is my Jobseeker.php model use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableTrait; use Illuminate\Auth\Reminders\RemindableInterface; class Jobseeker extends Eloquent implements UserInterface, RemindableInterface { use UserTrait, RemindableTrait; protected $fillable = ['fullname','mothersname','fathersname','gender', 'marital','religion','dateofbirth','nationalid','email', 'password', 'password_temp', 'code', 'active']; protected $table = 'jobseekers'; public function getAuthPassword() { return $this->password; } public function qualifications() { return $this->hasMany('Qualification','jobseekers'); } } // This is my controller $user = Auth::jobseeker()->get(); $jobseeker = Jobseeker::find($user->id); $input = Input::all(); $qualification = Qualification::create(array ( 'level_of_education' => $input['level_educationText'], 'exam_title' => $input['exam_titleText'], 'institute_name' => $input['institute_nameText'], 'insOther' => $input['insOtherText'], 'result' => $input['resultText'], 'year_of_passing' => $input['year_passingText'], 'duration' => $input['durationText'], 'achievement' => $input['achievementText'] ) ); 1. $qualification->jobseeker()->save($user->id); 2. $qualification->Jobseeker()->save($user->id); 3. $qualification->Jobseeker()->attach($user->id); } I tried three of them but it shows the error messages like:: BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder::save() why it is shown? how to solve this problem. Plz help..Try this:
$qualification = new Qualification(array (
'level_of_education' => $input['level_educationText'],
'exam_title' => $input['exam_titleText'],
'institute_name' => $input['institute_nameText'],
'insOther' => $input['insOtherText'],
'result' => $input['resultText'],
'year_of_passing' => $input['year_passingText'],
'duration' => $input['durationText'],
'achievement' => $input['achievementText']
) );
$jobseeker->qualifications()->save($qualification);
And considering you have $fillable
member defined, you should be able to just pass $input
array directly to Qualification
constructor:
$qualification = new Qualification( $input );
$jobseeker->qualifications()->save($qualification);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community