title: foreach() argument must be of type array|object, string given
body: <p>I am quite new to laravel and I have a weird problem with foreach() blade directive.
  the problem is when I want to iterate over a collection it throws an error and says:</p>
  <pre><code>foreach() argument must be of type array|object, string given
  </code></pre>
  <p>but I have printed the collection using print_r() method and it the variable does not hold any string, it hold a collection object.</p>
  <p>that is the piece of code that throws the error while reaching the foreach directive:</p>
  <pre><code>&lt;section class=&quot;col-span-8 col-start-5 mt-10 space-y-6&quot;&gt;
       {{print_r($post-&gt;comments)}}
       @foreach($post-&gt;comments as $comment) // here
            &lt;x-post-comment :comment=&quot;$comment&quot;&gt;&lt;/x-post-comment&gt;
       @endforeach
  &lt;/section&gt;
  </code></pre>
  <p>basically, in the above code in the foreach I have a Eloquent relationship and between Post and Comment Models and the relationship works perfectly in tinker, but here it says that it is not a collection or an array. also, I have a post-comment blade component that renders the layout for a commment inside the foreach.</p>
  <p>and that is the implementation of the relationship between each post and its comments:</p>
  <pre><code> function comments()
      {
          return $this-&gt;hasMany(Comment::class);
      }
  </code></pre>
  <p>as I mentioned, the above relationship works perfectly, but I don't know what is wrong with it.</p>
  <p>any help would be appreciated!</p>