title: Trying to use string as foreign key in laravel
body: <p>I am just a beginner and trying to use string as foreign key in laravel but getting this error while fetching the data:-</p>
  <blockquote>
  <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'read' in 'where clause' (SQL: select <code>from</code> as sender_id, count(<code>from</code>) as messages_count from <code>messages</code> where <code>to</code> = d3c364bb-0982-46ba-869a-24dbb2c50aea and <code>read</code> = 0 group by <code>from</code>)</p>
  </blockquote>
  <p>In here I am fetching users contacts from received and a group of unread message count</p>
  <pre><code>public function get(){
          $contacts = DB::table('received')
      -&gt;where('user_id', Auth::user()-&gt;uuid)
      -&gt;get();
      
       $unreadIds = Message::select(\DB::raw('`from` as sender_id, count(`from`) as messages_count'))
              -&gt;where('to', Auth::user()-&gt;uuid)
              -&gt;where('read', false)
              -&gt;groupBy('from')
              -&gt;get();
  
         
          $contacts = $contacts-&gt;map(function($contact) use ($unreadIds) {
              $contactUnread = $unreadIds-&gt;where('sender_id', $contact-&gt;friends_id)-&gt;first();
  
              $contact-&gt;unread = $contactUnread ? $contactUnread-&gt;messages_count : 0;
  
              return $contact;
          });
  
      return response()-&gt;json($contacts);
          }
  </code></pre>
  <p><strong>Received Table:-</strong></p>
  <pre><code> public function up()
      {
          Schema::create('received', function (Blueprint $table) {
              $table-&gt;engine = 'InnoDB';
              $table-&gt;id();
              $table-&gt;string('user_id', 36);
              $table-&gt;unsignedBigInteger('friends_id');
              $table-&gt;string('list_no')-&gt;nullable();
              $table-&gt;string('name');
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  <p>This is from where i am fetching unread message count:-</p>
  <pre><code>public function up()
      {
          Schema::table('messages', function (Blueprint $table) {
              $table-&gt;engine = 'InnoDB';
              $table-&gt;boolean('read')-&gt;after('to', 36)-&gt;default(false);
          });
      }
  
      
      public function down()
      {
          Schema::table('messages', function (Blueprint $table) {
              $table-&gt;dropColumn('read');
          });
      }
  </code></pre>
  <p><strong>Here's Message table</strong></p>
  <pre><code>public function up()
      {
          Schema::create('messages', function (Blueprint $table) {
             $table-&gt;engine = 'InnoDB';
              $table-&gt;id();
              $table-&gt;string('from', 36);
              $table-&gt;string('to', 36);
              $table-&gt;text('text');   
              $table-&gt;string('list_no')-&gt;nullable(); 
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  <p>Can anyone please help me through this.</p>