title: Laravel storing only the last element of the array in the DB table (foreach loop)
body: <p>I uploaded multiple images on the database:</p>
  
  <p><a href="https://i.stack.imgur.com/qaFgu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qaFgu.png" alt="enter image description here"></a>
  In the next step I'm trying to change the value of alt column based on dynamically created inputs located on the blade page:</p>
  
  <p><a href="https://i.stack.imgur.com/qtqGv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qtqGv.png" alt="enter image description here"></a></p>
  
  <p>But after I submit and entered values in HTML inputs, LARAVEL app stores only value  (example2) from last HTML input in both images(records) within the alt column.</p>
  
  <p><a href="https://i.stack.imgur.com/MMZhD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MMZhD.png" alt="enter image description here"></a></p>
  
  <p><strong>altPictures.blade.php</strong></p>
  
  <pre><code>@extends('layout')
  
  @section('content')
  
      @include('nav')
  
      &lt;div class="container"&gt;
          &lt;h1 class="center-align"&gt;Insert alt Text for uploaded images&lt;/h1&gt;
          @if(count($errors) &gt; 0)
              &lt;div class="materialert warning" id="close-dialog"&gt;
                  &lt;i class="material-icons"&gt;warning&lt;/i&gt;
                  &lt;span&gt;
                      @foreach($deletePost -&gt;all() as $error)
                          &lt;ul&gt;
                              &lt;li&gt;{{$error}}&lt;/li&gt;
                          &lt;/ul&gt;
                      @endforeach
                  &lt;/span&gt;
              &lt;/div&gt;
          @endif
  
          {!! Form::open(['action' =&gt;  ['HomepageController@altPicturesPost', $language-&gt;url], 'method' =&gt; 'POST', 'files' =&gt; true]) !!}
  
          @foreach($pictures as $picture)
  
              &lt;img class="center-block img-responsive" src="/uploads/homepage_galery/{{ $picture-&gt;filename }}"/&gt;
  
              &lt;div class="form-group"&gt;
                  {{Form::label('naslov', 'Type alt text of image')}}
                  {{Form::text('alt['.$picture-&gt;id.']', '', ['id' =&gt; 'alt', 'class' =&gt; ($errors-&gt;has('naslov')) ? 'form-control is-invalid' : 'form-control',  'placeholder' =&gt; 'Type alt text of image '])}}
              &lt;/div&gt;
  
              {!! Form::hidden('id['.$picture-&gt;id.']', $picture-&gt;id) !!}
  
          @endforeach
  
          {{Form::submit('Submit', ['class' =&gt; 'btn blog-button']) }}
  
          {!! Form::close() !!}
      &lt;/div&gt;&lt;!-- /container --&gt;
  
  @endsection
  </code></pre>
  
  <p><strong>HomeGaleryConroller</strong></p>
  
  <pre><code>public function altPictures($url)
  {
      $languages = Language::where('url', '=', $url)-&gt;get();
      $language = Language::where('url', '=', $url)-&gt;first();
      if (count($language) == 0) {
          abort(404);
      }
  
      $languagesLists = Language::all();
      $languagesSelect = Language::pluck('title', 'id');
      $categories = Category::with('firstsubcategories')-&gt;get();
      $subcategories = SubCategory::All();
      $secondsubcategories = SecondSubCategory::All();
      $listings = CategoryListing::All();
      $navposts = Post::all();
      $navproducts = Product::all();
      $subListings = SubcategoryListing::All();
      $SecSubListings = SecSubcategoryListing::All();
      $pictures = HomeGalery::all();
  
      return view('homepageGalery/altPictures', ['languages' =&gt; $languages, 'language' =&gt; $language, 'languagesLists' =&gt; $languagesLists, 'categories' =&gt; $categories, 'listings' =&gt; $listings, 'subcategories' =&gt; $subcategories, 'secondsubcategories' =&gt; $secondsubcategories, 'adminpaneListings' =&gt; $adminpaneListings, 'navposts' =&gt; $navposts, 'navproducts' =&gt; $navproducts, 'adminpanelSublistings' =&gt; $adminpanelSublistings, 'adminpanelSecSublistings' =&gt; $adminpanelSecSublistings, 'subListings' =&gt; $subListings, 'SecSubListings' =&gt; $SecSubListings, 'languagesSelect' =&gt; $languagesSelect, 'pictures' =&gt; $pictures]);
  
  }
  
  
  public function altPicturesPost(Request $request, $url)
  {
      foreach ($request-&gt;input('alt') as $alt) {
          $galeries = HomeGalery::wherein('id', $request-&gt;input('id'))-&gt;get();
          foreach ($galeries as $galery) {
              $galery-&gt;alt = $alt;
              $galery-&gt;save();
          }
      }
  
      return redirect()-&gt;route('adminpanel.homepage.galery', $url);
  }
  </code></pre>