jeudi 18 janvier 2018

Cannot create relation entry of object in pivot through create method on relation function

I've set up a morphToMany relationship to assign following relationships

  • A group can belong to many categories
  • A category can have many groups
  • A user can belong to many groups
  • A group can have many users

I've implemented Ramsey\Uuid for default Uuid for ID's

Creating relationship entry to pivot table doesn't work. If I execute the following query,

App\Category::first()->groups()->create(['name' => 'Some Group', 'user_id' => App\User::first()->id]);

It creates the group instance in database, but fails with following error while creating pivot relation in role_assignments table. No relation entry is created in pivot table.

ErrorException (E_RECOVERABLE_ERROR) Object of class Ramsey\Uuid\Codec\StringCodec could not be converted to string

Note: Successfully able to fetch entries using relationships. Its just that I can't create successful entries through those relationship functions.

Pivot Table Schema:

Pivot Table Schema

UuidGen - Uuid Generator Trait

Uuid Generator Trait

Category Model

enter image description here

Group Model

Group Model

User Model

User Model

Feel free to respond any possible solutions and ask for, if need any more data for analysis to rectify the problem.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mMk7Dr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire