david19
1 month ago
160
1
Laravel

Why @foreach override my Textarea

Posted 1 month ago by david19

Hello Team. I dont understand why PHP do that. Because i am a beginner. I have a Edit View with 2 Formgroups:

<div class="form-group">
          <div class="card bg-darkblue text-white border border-white">
          <div class="card-header bg-darkblue text-white">
          CHANGE PARENTCATEGORY?
          </div>
          <div class="card-body bg-darkblue text-white">
          <label for="exampleFormControlSelect1"></label>
          <select  name="parent_id" class="form-control bg-darkblue text-white" id="exampleFormControlSelect1">
          <option value="0">No</option>
          @foreach($product_categories as $product_category)
          <option value="{{$product_category->id}}">{{$product_category->name}}</option>

          @endforeach
          </select>
          </div>
          <div class="card-footer bg-darkblue text-white">
          </div>
          </div>
          </div>
<div class="form-group">
          <div class="card bg-darkblue text-white border border-white mt-5">
          <div class="card-header bg-darkblue text-white">
          CATEGORY DESCRIPTION
          </div>
          <div class="card-body bg-darkblue text-white">
          <textarea class="form-control" id="summernote" rows="3" name="description" value="{{$product_category->description}}">{{$product_category->description}}</textarea>
          <script>
          $('#summernote').summernote({
          placeholder: '',
          tabsize: 2,
          height: 100
          });
          </script>
          </div>
          <div class="card-footer bg-darkblue text-white">
          </div>
          </div>
          </div>

Why this foreach loop override my Textvalue in the Textarea? I closed the loop before, i dont understand. If i change the loop name:

@foreach($product_categories as $product_cat)
          <option value="{{$product_category->id}}">{{$product_cat->name}}</option>

          @endforeach

it will works, but then it will not save the parent category.

Please sign in or create an account to participate in this conversation.