title: Laravel : Call to undefined method Illuminate\Database\Eloquent\Collection::save()
body: <p>I am basically trying to get a specific row from my table and update it, however, I end up getting a collection for which save method is not defined as the error says in my Title. Can you please tell me what is wrong in the below code. I have also tried it without the get method. But in that case I get a different error. Also, please let me know if there is any better approach to retrieve a row from a table with two primary keys(userId, folderName) in this case. Thank you :)</p>
  
  <pre><code>$tempFolder =   Message_Folders::where('userId',"=",1)-&gt;where('folderName',"=",$imap_folder['name'])-&gt;get();
  if($tempFolder==null){//If not existing, however in this example assume that it exists
          $tempFolder =  new Message_Folders();
          $tempFolder-&gt;userId = 1;    
          $tempFolder-&gt;folderName = $imap_folder['name'];
          }
          $tempFolder-&gt;flags = $imap_folder['status']-&gt;flags;
          $tempFolder-&gt;messages = $imap_folder['status']-&gt;messages;
          $tempFolder-&gt;recent = $imap_folder['status']-&gt;recent;
          $tempFolder-&gt;unseen = $imap_folder['status']-&gt;unseen;
          $tempFolder-&gt;uidnext = $imap_folder['status']-&gt;uidnext;
          $tempFolder-&gt;uidvalidity = $imap_folder['status']-&gt;uidvalidity;
          $tempFolder-&gt;save();
  </code></pre>
  
  <p>Edit 1:</p>
  
  <p>After Updating the code as mentioned in the first answer, now I get a new error.</p>
  
  <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update <code>message_folders</code> set <code>recent</code> = 4, <code>updated_at</code> = 2014-03-08 13:34:10 where <code>id</code> is null) </p>
  
  <p>Please refer to the code below:( Also, if all the values are same then it works fine(since the update is actually not happening))</p>
  
  <pre><code>$tempFolder =   $this-&gt;folders-&gt;where('userId',"=",1)-&gt;where('folderName',"=",$imap_folder['name'])-&gt;first();
          if($tempFolder==null){
          $tempFolder =  new Message_Folders();
          $tempFolder-&gt;userId = 1;    
          $tempFolder-&gt;folderName = $imap_folder['name'];
          }
          $tempFolder-&gt;flags = $imap_folder['status']-&gt;flags;
          $tempFolder-&gt;messages = $imap_folder['status']-&gt;messages;
          $tempFolder-&gt;recent = 4;
          $tempFolder-&gt;unseen = $imap_folder['status']-&gt;unseen;
          $tempFolder-&gt;uidnext = $imap_folder['status']-&gt;uidnext;
          $tempFolder-&gt;uidvalidity = $imap_folder['status']-&gt;uidvalidity;
  
          $tempFolder-&gt;save();
  </code></pre>
  
  <p>Edit 2: Part of migration file for the table mentioned in the above code:</p>
  
  <pre><code>public function up()
      {
          Schema::create('message_folders', function(Blueprint $table) {
             $table-&gt;integer('userId');
             $table-&gt;string('folderName', 200);
             $table-&gt;integer('flags');
             $table-&gt;integer('messages');
             $table-&gt;integer('recent');
             $table-&gt;integer('unseen');
             $table-&gt;integer('uidnext');
             $table-&gt;integer('uidvalidity');
             $table-&gt;timestamps();
             $table-&gt;primary(array('userId','folderName'));
          });
      }
  </code></pre>