noblemfd
2 months ago
462
11
Laravel

gender dropdown is not loading data on edit blade

Posted 2 months ago by noblemfd

I have this controller:

public $genders = [
    "0" => "Female",
    "1" => "Male",
];

public $maritalstatuses = [
    "1" => "Single",
    "2" => "Married",
    "3" => "Separated",
    "4" => "Divorced",
    "5" => "Widow(er)",
    "6" => "Other",
]; 

public function create()
{
    $designations       =       Designation::all();
     return view('hr.employees.create')
           ->with('designations', $designations)
            ->with('maritalstatuses', $this->maritalstatuses)
            ->with('genders', $this->genders);
}

public function edit($id)
{
     $designations       =       Designation::all();
     $employee = HrEmployee::where('id', $id)->first();
     return view('hr.employees.edit')
	    	->with('designations', $designations)
	->with('maritalstatuses', $this->maritalstatuses)
            ->with('genders', $this->genders);
}

edit view blade

edit.blade

   <form  action="{{route('hr.employees.update', ['id'=>$employee->id])}}" method="post" class="tab-wizard wizard-circle form" enctype="multipart/form-data">
    {{ csrf_field() }}

          <div class="col-12 col-sm-4">
            <div class="form-group">
              <label class="control-label"> Position/Designation:</label>
              <select class="form-control select2bs4" data-placeholder="Choose Position/Designation" tabindex="1" name="employee_designation_id" style="width: 100%;">
                <option value="">Select Position/Designation</option>
                <option selected disabled>Select Position/Designation</option>
                   @if($designations->count() > 0 )
                     @foreach($designations as $designation)
                       <option value="{{$designation->id}}" @if($designation->id == $employee->designation_id) selected @endif>{{$designation->designation_name}}</option>
                     @endforeach
                   @endif
              </select>
            </div>
            <!-- /.form-group -->
          </div>

          <div class="col-12 col-sm-4">
            <div class="form-group">
                <label class="control-label"> Marital Status:</label>
              <select class="form-control select2bs4" data-placeholder="Choose Marital Status" tabindex="1" name="marital_status_id" style="width: 100%;">
                <option value="">Select Marital Status</option>
                <option selected disabled>Select Marital Status</option>
                     @foreach($maritalstatuses as $maritalstatus)
                       option value="{{$k}}" @if($employee->maritalstatus == $k) selected @endif>{{$maritalstatus}}</option>
                     @endforeach
              </select>
            </div>
            <!-- /.form-group -->
          </div>

          <div class="col-12 col-sm-4">
            <div class="form-group">
              <label class="control-label"> Gender:<span style="color:red;">*</span></label>
              <select class="form-control select2bs4" data-placeholder="Choose Gender" tabindex="1" name="gender_code" style="width: 100%;">
                <option value="">Select Gender</option>
                 <option selected disabled>Select Gender</option>
                     @foreach($genders as $k => $gender)
                       option value="{{$k}}" @if($employee->gender == $k) selected @endif>{{$gender}}</option>
                     @endforeach
              </select>
            </div>
            <!-- /.form-group -->
          </div>

The create view blade works perfectly. On the edit view blade, designation is loaded correctly. But for the gender and marital status select dropdown, nothing is loaded.

What is really wrong?

Thanks

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