Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #360
    jacob_smith
    Participant

    Error when when trying to insert data in pivot table of a many to many relationship:

    SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: ‘Brandi Morissette III’ for column project2.unit_user.user_id at row 2 (Connection: mysql, SQL: insert into unit_user (unit_id, user_id) values (1, 1), (1, Brandi Morissette III), (1, kelley88@example.net), (1, 2023-03-13T03:59:17.000000Z), (1, 2023-03-13T03:59:17.000000Z), (1, 2023-03-13T03:59:17.000000Z))

    #361

    Can you share the code? Specifically the one that insert the data to the tables

    #363
    jacob_smith
    Participant

    So basically I am attaching a model in a many to many relationship in livewire component:

    Livewire component:

    public $model;

    public function attach($modeltoAttached) {

    $this -> model() -> attach($modeltoAttached);

    }

    #364

    It looks like you are attaching a a whole model. When you do that it will also attach all its properties including timestamps date on your model. In the attach method, specify only the id as follows:

    public function attach($modeltoAttached -> id) {

    $this -> model() -> attach($modeltoAttached -> id);

    }

    #365
    jacob_smith
    Participant

    It works. Thank you

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.