jeudi 8 juin 2017

Laravel Records Relationship issue

I have one to many relationship between Applicant and pendingJob, Where my Applicant model have cnic primary key, Where pendingJob have applicant_id and pointing it to Applicant model cnic column as foreign key.

Applicant model :

protected $primaryKey = 'cnic';

public function pending_jobs() {
    return $this->hasMany('App\PendingJobs', 'applicant_id');
}

PendingJob model :

public function pending_jobs() {
    return $this->hasMany('App\PendingJobs', 'applicant_id');
}

I am inserting record in Applicant like :

$req = new \App\Applicant;
$req->full_name = $request->get('full_name');
$req->cnic = $request->get('cnic');
$req->mobile_number = $request->get('mobile_number');
$req->save();

Then record in PendingJob :

$reqr = new \App\PendingJob;
$reqr->applicant_id = $request->get('cnic');
$reqr->job_type = 'residence';
$reqr->status = 'pending';
$reqr->save();

The record saves and cnic which is the primary key of the Applicant and the Pendingjob's applicant_id which is pointing to the Applicant's cnic comes the same.

But

The relationship does not loads, Manual record insertion from phpmydamin works fine.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire