title: How to fix "Invalid datetime format: 1366 Incorrect integer value: " error in laravel 5.7?
body: <p>I am trying to create a records with multiple one to one relationships in laravel 5.7. The following is how I am doing it,</p>
  
  <p><strong>Migrations</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>   //in create_invoices_table.php
     public function up()
       {
             Schema::create('invoices', function (Blueprint $table) {
                  $table-&gt;increments('id');
                  $table-&gt;string('name');
                  $table-&gt;integer('service_id')-&gt;unsigned()-&gt;nullable();
                  $table-&gt;integer('account_id')-&gt;unsigned()-&gt;nullable();
                  $table-&gt;timestamps();
  
                  // foreign keys
                  $table-&gt;foreign('service_id')-&gt;references('id')-&gt;on('services')-&gt;onDelete('cascade');
                  $table-&gt;foreign('account_id')-&gt;references('id')-&gt;on('accounts')-&gt;onDelete('cascade');
             });
       }
  
  
       // in create_accounts_table.php
       public function up()
       {
           Schema::create('accounts', function (Blueprint $table){
                $table-&gt;increments('id');
                $table-&gt;string('name');
                $table-&gt;string('email');
                $table-&gt;timestamps()
           )};
       }
  
  
       // in the create_services_table.php
       public function up()
       {
            Schema::create('services', function (Blueprint $table){
                $table-&gt;increments('id');
                $table-&gt;string('name');
                $table-&gt;float('price', 8, 2);
                $table-&gt;timestamps();
           )};
       }
  </code></pre>
  
  <p><strong>Models</strong></p>
  
  <p>The <code>Account</code> model has a <code>hasOne()</code> function which defines a one to one relationship with the invoices. i.e.
  </p>
  
  <pre><code>   //in Account.php
     public function invoice() {
         return $this-&gt;hasOne('App\Invoice');
     }
  </code></pre>
  
  <p>The <code>Service</code> model has a <code>hasOne()</code> function which defines a one to one relationship with the invoices as well. i.e.
  </p>
  
  <pre><code>   //in Service.php
     public function invoice() {
         return $this-&gt;hasOne('App\Invoice');
     }
  </code></pre>
  
  <p>The inverses one to one relationshipa are defined in the <code>invoice model</code> using the <code>belongsTo()</code> functions as follows
  </p>
  
  <pre><code>     //in Invoice.php
       public function account() {
           return $this-&gt;belongsTo('App\Account');
       }
  
       public function service() {
           return $this-&gt;belongsTo('App\Service');
       }
  </code></pre>
  
  <p><strong>InvoiceController.php</strong></p>
  
  <p>Now I am trying to create an invoice record which I am trying to associate with the <code>account</code> as well as <code>service</code> models as follows
  </p>
  
  <pre><code>     public function store(Request $request)
       {
            $account = Account::find([$request-&gt;get('aid')]);
            $service = Service::find([$request-&gt;get('sid')]);
  
            $invoice = new Invoice();
            $invoice-&gt;name = self::getAccountName($request-&gt;get('aid'));
  
            // save the invoice to database
            $invoice-&gt;save();
  
            // add service and account to the invoice
            $invoice-&gt;account()-&gt;associate($account)-&gt;save();
            $invoice-&gt;service()-&gt;associate($service)-&gt;save();
  
  
            return redirect()-&gt;route('invoices.index');
       }
  </code></pre>
  
  <p>And this give me the following error which I am failing to fix.</p>
  
  <blockquote>
    <p>Illuminate \ Database \ QueryException (22007) SQLSTATE[22007]:
    Invalid datetime format: 1366 Incorrect integer value:
    '[{"id":1,"name":"Example Name","email":"example@email.com"' for column 'account_id' at row 1 (SQL: update <code>invoices</code> set <code>account_id</code> = [{"id":1,"name":"Example Name","email":"example@email.com","created_at":"2019-01-02 15:37:41","updated_at":"2019-01-02 15:37:41"}], <code>updated_at</code> = 2019-01-02 16:05:13 where <code>id</code> = 17)</p>
  </blockquote>
  
  <p>Please, help me how I can fix this error. </p>