title: Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query
body: <p>I'm using MySQL in development, storing base64 image in <code>longblob</code> data type.</p>
  
  <p>But I'm getting error below when trying to insert data after I changed database to MS SQL &amp; data type to <code>varbinary(max)</code></p>
  
  <blockquote>
    <p>Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query</p>
  </blockquote>
  
  <p>So I put a mutator to get this around as below,</p>
  
  <pre><code>public function setItemPictureAttribute($value)
  {
      $this-&gt;attributes['item_picture'] = DB::raw('CONVERT(VARBINARY(MAX), "'. $value .'")');
  }
  </code></pre>
  
  <p>but I'm getting error below when trying to store the base64 image;</p>
  
  <blockquote>
    <p>The identifier that starts with '/9j/4QxnRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAMAAAExAAIAAAAeAAAAcgEyAAIAAAAUAAAAkIdp' is too long. Maximum length is 128`</p>
  </blockquote>
  
  <p>What did I miss?</p>
  
  <p>EDIT: Somehow I got this work after I changed to <code>$this-&gt;attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");</code>; notice that I switched the double quote with single quote and vice versa in <code>DB::raw</code>. Maybe someone can explain why</p>