title: Laravel query builder returns object or array?
body: <p>I'm building a very simple web app with Laravel.</p>
  
  <p>I've built two separate Controllers, which each return two separate views, as follows:</p>
  
  <p>ProfileController:</p>
  
  <pre><code>class ProfileController extends BaseController {
  
      public function user($name)
      {
          $user = User::where('name', '=', $name);
  
          if ($user-&gt;count())
          {
              $user = $user-&gt;first();
              $workout = DB::table('workouts')-&gt;where('user_id', '=', $user-&gt;id)-&gt;get();
  
              Return View::make('profile')
                      -&gt;with('user', $user)
                      -&gt;with('workout', $workout);
          }
  
          return App::abort(404);
      }
  }
  </code></pre>
  
  <p>WorkoutController:</p>
  
  <pre><code>class WorkoutController extends BaseController {
  
      public function workout($name)
      {
          $workout = DB::table('workouts')-&gt;where('name', '=', $name)-&gt;first();
  
          if ($workout)
          {
              Return View::make('add-exercise')
                      -&gt;with('workout', $workout);
          }
  
          return App::abort(404);
      }
  }
  </code></pre>
  
  <p>What is confusing me is what I had to do in order to pass a single <code>workout</code> object to each view. As you might have noticed the query builders for <code>workout</code> are different:</p>
  
  <pre><code>$workout = DB::table('workouts')-&gt;where('user_id', '=', $user-&gt;id)-&gt;get();
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$workout = DB::table('workouts')-&gt;where('name', '=', $name)-&gt;first();
  </code></pre>
  
  <p>On the <code>profile</code> view, I get an object using the <code>-&gt;get();</code> method, but on the <code>add-exercise</code> view, I must use <code>-&gt;first();</code> or I will otherwise get an array with only one index, where I can then access the object, i.e. <code>$workout[0]-&gt;name</code> instead of <code>$workout-&gt;name</code>.</p>
  
  <p>Why is this? Shouldn't I be able to use either <code>get</code> and/or <code>first</code> in both controllers and expect the same type of result from both since I want the same thing from the same table?</p>