title: Why isn't this WHERE clause accepting a variable? Laravel 5.3
body: <p>I have this function here: </p>
  
  <pre><code>public function move() {
  
          $prefs = DB::table('users')-&gt;select('id', 'Preferences')-&gt;where('Preferences', '!=', '')-&gt;get();
  
              foreach ($prefs as $pref) {
                   $tags = $pref-&gt;Preferences;
                   $tag = explode(',', $tags);
                   foreach ($tag as $t) {
                       $new = DB::table('prefs')-&gt;select('id', 'tag')-&gt;where('tag', '=', $t)-&gt;get();
                       $taguser = new Tag(array(
                                         'user_id' =&gt; $pref-&gt;id,
                                         'tag_id' =&gt; $t,
                                         'tagsid' =&gt; $new-&gt;id
                                        ));
                       $taguser-&gt;save(); //save in table
                   }
               }
               return view('refactor');
      }
  </code></pre>
  
  <p>It basically just grabs the data from an old database table which wasn't properly set up, splits up the data, compares it with a list of the preferences in another table and gets that data id, then prints the tag, the user id, and the preference id into a pivot table. </p>
  
  <p>Or that's what it's supposed to do. Right now it's telling me the id from the prefs table is undefined. That last bit there <code>'tagsid' =&gt; $new-&gt;id</code>  &lt;= apparently that doesn't exist. </p>
  
  <p>But it should. What did I do wrong? </p>
  
  <p>Here's a piece of the error:</p>
  
  <pre><code>Undefined property: Illuminate\Support\Collection::$id
      at HandleExceptions-&gt;handleError('8', 'Undefined property: Illuminate\Support\Collection::$id', 'C:\xampp\htdocs\Missionseek2\app\Http\Controllers\RefactorController.php', '29', array('prefs' =&gt; object(Collection), 'pref' =&gt; object(stdClass), 'tags' =&gt; '1-3,1-5,1-4,2-3,3-2,3-9,3-3,3-4,3A-5,3A-8,5-2,8-4,8-8,8-13,9-5,7A-2,7A-4,7A-10', 'tag' =&gt; array('1-3', '1-5', '1-4', '2-3', '3-2', '3-9', '3-3', '3-4', '3A-5', '3A-8', '5-2', '8-4', '8-8', '8-13', '9-5', '7A-2', '7A-4', '7A-10'), 't' =&gt; '1-3', 'new' =&gt; object(Collection))) in RefactorController.php line 29
  </code></pre>