vendredi 19 juillet 2019

How to store a branch-office in one agency that belongs to one user?

I need to store one branch office (a model in my database) in a agency(another model) (both have a one to many relationship) that belongs to a user. So far I reach to store the branch office in the agency, but the agency is not related to the user. When I change the user, I get an empty json.

So far I have this

$info= $this->validate($request, BrancOffice::validationRules());

$agency= Agency::find(11); 

$branch_office= $agency->branch_offices()->create($data);

$agency->branch_offices()->save($branch_office);

return ($agency);


Agency model: 
public function branch_offices()
{
return $this->hasMany('Jobpoint\Jobboard\BranchOffice');
}

Branch Office Model:

public function agency()
{
    return $this->belongsTo('Jobpoint\Jobboard\Agency');
}

BranchOffice migration:

$table->integer('agency_id')->unsigned();
$table->foreign('agency_id')->references('id')->on('agencies');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire