vendredi 1 mars 2019

Lumen 5.1 - many to many sync is missing data

I'm trying to create a reusable method for creating a relationship for a many to many pivot table but it seems to be missing the listing_id when trying to sync the data.

$model = $this->model->findOrFail($model_id)->with($relation);
return $model->getRelation($relation)->sync($data);

Returns:

integrity constraint violation: 1048 Column 'listing_id' cannot be null (SQL: insert into `tenants_listings` (`created_at`, `listing_id`, `tenant_id`, `updated_at`) values (2019-03-01 11:10:36, , ef4c9d60-a7a3-3340-8dd0-a901d624cd97, 2019-03-01 11:10:36)

This works perfectly fine when done like this:

$model = $this->model->findOrFail($model_id)->tenants();
return $model->sync($data);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire