title: Laravel - Foreach loop Trying to get property of non-object
body: <p>I have a database table with</p>
  
  <p><code><strong>id | name | url |</strong> 
    1 | Bike | bike|
    2 | Auto | auto|
  </code></p>
  
  <p>I want to fetch the all <strong>names</strong> from the table to view with foreach loop. But it returns</p>
  
  <blockquote>
    <p>Trying to get property of non-object</p>
  </blockquote>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function category($url, request $id)
  {
      $cat = Category::where('url', $url)-&gt;firstorfail();
      return view ('view', compact('category'));  
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>class Category extends Model
  {
      protected $fillable = ['name', 'url'];
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@foreach($category as $cat)
      {{ $cat-&gt;name }}
      //{{ $cat['name] }} does not return anything.
  @endforeach
  
  //{{ $cat-&gt;name }} returns only one category name
  </code></pre>
  
  <p>I saw <a href="https://stackoverflow.com/questions/23789749/foreach-error-trying-to-get-property-of-non-object" title="Similar Queston">enter link description here</a>, I couldn't solve it.</p>