mercredi 19 mai 2021

4 Dropdowns select in form laravel

I am trying to add more than 3 dropdown select fields on the form. can you guide me on how can I manage this without using ajax? I am new to laravel. I want to add the company, department, and 2 other fields with dropdown fetching data from the database.

View Blade code

<select type="text" class="form-control select2" id="company" name="company">
            @foreach ($companies as $company)
            <option value="" >  </option>
            @endforeach
        </select>
    </div>

    <div class="col-md-3 form-group">
            <label for="department" class="form-label">Department</label>
            <select type="text" class="form-control select2" id="department" name="department">
                @foreach ($departments as $department)
                <option value="" >  </option>
                @endforeach

            </

Controller side code

  public function create()
    {
        $companies = Company::select('id', 'companyName')->get();
        return view('posts.accesscontrol.create', compact('companies'));

        $departments = Department::select('id', 'departmentName')->get();
        return view('posts.accesscontrol.create', compact('departments'));
    }



Aucun commentaire:

Enregistrer un commentaire