Answers for "Looping Through Select Option Dropdown with Laravel Collective"

PHP
0

Looping Through Select Option Dropdown with Laravel Collective

//Controller
public function create()
{
  
        $departments = Departments::all();
        $select = [];
        foreach($departments as $department){
            $select[$department->id] = $department->title;
        }
        return view('employees.create', compact('select'));
}

//View
{!!Form::open(['method'=>'Post', 'action'=>'EmployeeController@store','files'=>true])!!}
@csrf
  <div class="form-group col-md-12">
	  {!! Form::label('Job Status')!!}
  </div>
  <div class="form-group col-md-6">
     {!! Form::label('Role')!!}
     {!!Form::select('role_id', ['1' => 'Employee'], 'User', ['class' => 'form-control' ]) !!}
  </div>

  <div class="form-group col-md-6">
	 {!! Form::label('Position')!!}
	 {!!Form::select('job_id', ['1' => 'Developer', '2' => 'Full Stack Developer', '4' =>
                    'Intern'],['class' => 'form-control' ]) !!}
  </div>
  <div class="form-group col-md-6">
     {!! Form::label('Choose a Department')!!}
	 {!! Form::select('department_id', $select, null, ['class'=>'form-control']) !!}
  </div>
  <div class="login100-form-btn">
     {!!Form::submit('Submit', ['class'=>'btn'])!!}
	 {!!Form::close() !!}
  </div>
Posted by: Guest on October-01-2020

Code answers related to "Looping Through Select Option Dropdown with Laravel Collective"

Browse Popular Code Answers by Language