title: Array Count - Laravel
body: <p><a href="https://i.stack.imgur.com/pTv2K.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pTv2K.jpg" alt="enter image description here"></a></p>
  
  <p>How can i get a count of the number of arrays of the attached screenshot.
  In this scenario the number i want is <strong>2</strong></p>
  
  <pre><code>public function update(Request $request, $jobId)
      {
          //dd($request);
          // cast into a collection use the collect() helper
          $collection = collect($request);
  
          for ($i=0; $i &lt; $collection-&gt;count(); $i++) {
            //dd(count($request));
            $subJob = SubJob::Find($request-&gt;get('id')[$i]);
            $subJob-&gt;job_id = $jobId;
            $subJob-&gt;name = $request-&gt;get('name')[$i];
            $subJob-&gt;size = $request-&gt;get('size')[$i];
            $subJob-&gt;medium = $request-&gt;get('medium')[$i];
            $subJob-&gt;feature = $request-&gt;get('feature')[$i];
            $subJob-&gt;qty = $request-&gt;get('qty')[$i];
            $subJob-&gt;price = $request-&gt;get('price')[$i];
            $subJob-&gt;total = $request-&gt;get('qty')[$i] * $request-&gt;get('price')[$i];
            $subJob-&gt;save();
       }
  </code></pre>
  
  <p><strong>$collection->count()</strong> gives the value <strong>9</strong></p>
  
  <p>Is there any other way of running the loop until the end?
  For example in blade we have <strong>$loop->last</strong> but here , i am working at the Controller level</p>
  
  <pre><code>&lt;form action="{{ route('employee.subjob.update',$job-&gt;id) }}" method="post"&gt;&lt;br&gt;
        @csrf
        @method('PUT')
        @foreach ($subJobs as $subJob)
          &lt;input type="hidden" name="id[]" value="{{$subJob-&gt;id}}"&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;input type="text" name="name[]" value="{{$subJob-&gt;name}}"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="size[]" value="{{$subJob-&gt;size}}"&gt;&lt;/td&gt;
            &lt;td&gt;
              &lt;textarea name="medium[]" rows="3" cols="20"&gt;{{$subJob-&gt;medium}}&lt;/textarea&gt;
            &lt;/td&gt;
            &lt;td&gt;
              &lt;textarea name="feature[]" rows="3" cols="20"&gt;{{$subJob-&gt;feature}}&lt;/textarea&gt;
            &lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="qty[]" value="{{$subJob-&gt;qty}}"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="price[]" value="{{$subJob-&gt;price}}"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="total[]" value="{{$subJob-&gt;total}}" disabled&gt;&lt;/td&gt;
          &lt;/tr&gt;
        @endforeach
        &lt;button type="submit" class="btn btn-primary"&gt; Update Job No {{$job-&gt;id}}&lt;/button&gt;
        &lt;/form&gt;
  </code></pre>