title: Laravel 8: Call to a member function user() on array
body: <p>I'm working with Laravel 8 to develop my forum project, and I wanted to add some like functionality to question that has been asked on forum by users.</p>
  <p>So here is a form on <code>question.blade.php</code>:</p>
  <pre><code>&lt;form action=&quot;{{ route('questions.likes', $show-&gt;id) }}&quot; method=&quot;POST&quot;&gt;
     @csrf
     &lt;button class=&quot;btn&quot;&gt;
        &lt;i class=&quot;fas fa-thumbs-up&quot;&gt;&lt;/i&gt; &lt;span&gt;{{ $show-&gt;likes-&gt;count() }}&lt;/span&gt;
     &lt;/button&gt;
  &lt;/form&gt; 
  </code></pre>
  <p>And then at <code>LikeController</code>, I added this:</p>
  <pre><code>public function store(Question $id, Request $request)
      {
          $id-&gt;likes()-&gt;create([
              'user_id' =&gt; $_REQUEST-&gt;user()-&gt;id,
          ]);
  
          return back();
      }
  </code></pre>
  <p>But now I get this error:</p>
  <pre><code>Call to a member function user() on array 
  </code></pre>
  <p>Which is referring to this line:</p>
  <pre><code>'user_id' =&gt; $_REQUEST-&gt;user()-&gt;id,
  </code></pre>
  <p>So what is going wrong here? I need to pass the user id who pressed on like button in order to update <code>likes</code> table. How can I solve this issue?</p>
  <p>I would really appreciate if you share any idea or suggestion about this with me...</p>
  <p>Thanks in advance.</p>