0

I have a problem here, I want to make an edit form, I want the province that appears in the edit form to be the province selected from the database, here my code

  <select name="provinsi" id="provinsi" class="form-control">
                <option value="">Pilih Provinsi</option>
                @foreach ($province as $prov)
                <option value="{{$prov->name}}">{{$prov->name}}</option>
                @endforeach
            </select>

here my controller code

public function ShowSantri(Request $request,$id)
    {

        $province = DB::table('provinces')->get();
        $profiles = Profile::find($request->id);

        return view('admin/modal/edit_santri',compact('profiles','province'));

2 Answers 2

1

You can try like this:

<select name="provinsi" id="provinsi" class="form-control">
    <option value="">Pilih Provinsi</option>
    @foreach ($province as $prov)
         <option value="{{$prov->name}}"
             @if ($profiles['provName'] == $prov->name)
                 selected
             @endif>
             {{$prov->name}}
         </option>
    @endforeach
</select>

Just I'm not sure what is name in your $profiles for province. But I think that is what you need.

Here and here are some examples.

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

1

Use or change this code based on your needs:

<option value="{{$prov->name}}" {{ $prov->name == $profiles->prov_id ? "selected" : "" }}>{{$prov->name}}</option>

I think the $prov->name should be $prov->id, if not, you can change $profiles->prov_id to $profiles->prov_name. It depends on your database structure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.