samedi 29 septembre 2018

drop-down selected option old value editing is in not working in laravel

I am trying to show the selected option value of drop-down and just used blew code and that's now working even I used the same trick for another table data and that is working fine. But I don't know why it's not working?

public function userEdit($id) {

    $user = User::find($id);
    $userType = User::first()->userType;
    $isActive = User::first()->isActive;
    $allRoles=Role::all();
    $role_user = $user->roles()->pluck('user_id','role_id')->toArray();

    return view('admin\userEdit',compact('user','allRoles','userType','isActive','role_user','selectedRole'));


}

<div class="form-group">
<label class="control-label col-md-3">User Type
    <span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-6">
    <div class="input-icon right">
        <i class="fa"></i>
        <select class="form-control"
            name="userType">

            <option @if(old('userType',$userType) == 'host') selected @endif>
                host
            </option>
            <option @if(old('userType',$userType) == 'visitor') selected @endif>
                visitor
            </option>
            <option @if(old('userType',$userType) == 'admin') selected @endif>
                admin
            </option>
            <option @if(old('userType',$userType) == 'operator') selected @endif>
                operator
            </option>

        </select>
    </div>
</div>

Can anyone help me to fix this that will show my old value when user will edit the data?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zE4XHT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire