title: Query works in MySQL but not via Lumen/Laravel - Numeric value out of range: 1416
body: <p>I am stumped... Quite simply, I am trying to update a geometry record in a MySQL database and for some reason, it is failing. However, when Lumen throws the <code>QueryException</code>, it shows the query that is being executed;</p>
  <pre><code>UPDATE `user_locations` SET `current_location` = ST_GeomFromText('POINT(1 1)') WHERE user_id = 1
  </code></pre>
  <p>The above query <em><strong>works</strong></em> when I execute it in MySQL via command line, but for some reason, it does not work via Laravel/Lumen/PDO/Eloquent (not sure which one is causing the issue).</p>
  <p>This is the error that is thrown:</p>
  <pre><code>SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field (SQL: update `user_locations` set `current_location` = ST_GeomFromText('POINT(1 1)') where `user_id` = 1)
  </code></pre>
  <p>I have tried everything that I can think of;</p>
  <ul>
  <li>Downgrading MySQL (I saw others having similar issues with Mysql 5.7)</li>
  <li>Dumping the query and bindings directly from Eloquent to see what is actually being sent to MySQL (see below)</li>
  <li>Changing the engine of the database (it is currently InnoDB)</li>
  <li>Removing the spatial index on the <code>current_location</code> column</li>
  </ul>
  <p>What else could be causing this? It cannot be MySQL as it works via command line, so it has to be something within Laravel/Eloquent/PDO surely?</p>
  <h2>Additional Information</h2>
  <ul>
  <li>I am running MySQL 5.7 (I have also tried 5.6 and it threw exactly the same error)</li>
  <li>I am using Lumen but don't think this is relevant as both Laravel and Lumen use Eloquent</li>
  <li>I am using <a href="https://github.com/grimzy/laravel-mysql-spatial" rel="nofollow noreferrer">https://github.com/grimzy/laravel-mysql-spatial</a> and this (I believe) is the relevant code:</li>
  <li><strong>Update</strong> - I don't think this is relevant, but there is another <code>point</code> field on this particular table but as I am not updating that field, it should be completely ignored in the query, thus, not relevant...</li>
  </ul>
  <p><em><strong>Builder extends Illuminate\Database\Eloquent\Builder</strong></em></p>
  <pre><code>/**
   * Update a record in the database.
   *
   * @param   array $values
   * @return  int
   */
  public function update(array $values) : int
  {
      foreach ($values as $key =&gt; &amp;$value) {
          if ($value instanceof GeometryInterface) {
              $value = $this-&gt;asWKT($value);
          }
      }
  
      return parent::update($values);
  }
  
  /**
   * Set the MySQL for the geometry field.
   *
   * @param   GeometryInterface $geometry
   * @return  string
   */
  protected function asWKT(GeometryInterface $geometry) : string
  {
      return $this-&gt;getQuery()-&gt;raw(&quot;ST_GeomFromText('&quot; . $geometry-&gt;toWKT() . &quot;')&quot;);
  }
  </code></pre>
  <p>In addition, I have also tried the following:</p>
  <p><em><strong>Illuminate\Database\Query\Builder</strong></em></p>
  <pre><code>public function update(array $values)
  {
      $sql = $this-&gt;grammar-&gt;compileUpdate($this, $values);
  
      dd($sql, $values, $this-&gt;cleanBindings(
          $this-&gt;grammar-&gt;prepareBindingsForUpdate($this-&gt;bindings, $values)
      ));
  
      return $this-&gt;connection-&gt;update($sql, $this-&gt;cleanBindings(
          $this-&gt;grammar-&gt;prepareBindingsForUpdate($this-&gt;bindings, $values)
      ));
  }
  </code></pre>
  <p>This outputs:</p>
  <pre><code>string(70) &quot;update `user_locations` set `current_location` = ? where `user_id` = ?&quot;
  array(1) {
    [&quot;current_location&quot;]=&gt;
    &amp;string(47) &quot;ST_GeomFromText('POINT(1 1)')&quot;
  }
  array(2) {
    [0]=&gt;
    &amp;string(47) &quot;ST_GeomFromText('POINT(1 1)')&quot;
    [1]=&gt;
    int(1)
  }
  </code></pre>