looping through select option dropdown with laravel collective

Solutions on MaxInterview for looping through select option dropdown with laravel collective by the best coders in the world

showing results for - "looping through select option dropdown with laravel collective"
Rafael
17 Jan 2019
1//Controller
2public function create()
3{
4  
5        $departments = Departments::all();
6        $select = [];
7        foreach($departments as $department){
8            $select[$department->id] = $department->title;
9        }
10        return view('employees.create', compact('select'));
11}
12
13//View
14{!!Form::open(['method'=>'Post', 'action'=>'EmployeeController@store','files'=>true])!!}
15@csrf
16  <div class="form-group col-md-12">
17	  {!! Form::label('Job Status')!!}
18  </div>
19  <div class="form-group col-md-6">
20     {!! Form::label('Role')!!}
21     {!!Form::select('role_id', ['1' => 'Employee'], 'User', ['class' => 'form-control' ]) !!}
22  </div>
23
24  <div class="form-group col-md-6">
25	 {!! Form::label('Position')!!}
26	 {!!Form::select('job_id', ['1' => 'Developer', '2' => 'Full Stack Developer', '4' =>
27                    'Intern'],['class' => 'form-control' ]) !!}
28  </div>
29  <div class="form-group col-md-6">
30     {!! Form::label('Choose a Department')!!}
31	 {!! Form::select('department_id', $select, null, ['class'=>'form-control']) !!}
32  </div>
33  <div class="login100-form-btn">
34     {!!Form::submit('Submit', ['class'=>'btn'])!!}
35	 {!!Form::close() !!}
36  </div>