vendredi 30 octobre 2015

Input::get() retrieving variable unique id instead of value laravel

I created a form and have a dropdown option which shows a list of option, after selecting the selected value it gets the description value instead. However I would like to retrieve the unique id instead of the description, how can I do so?

In my view.blade.php,

<div class="form-group">
    <label class="control-label col-sm-3" for="role_id">Role:</label>
    <div class="col-sm-5">
        <select class="form-control" id="role_id" name="role_id">
            @foreach ($roles as $role)
            <option>{{ $role->role_description }}</option>
            @endforeach
        </select>
    </div>
</div>

Then in my controller,

 // create the data for our user
            $user = new User;
            $user->name     = Input::get('name');
            $user->email    = Input::get('email');
            $user->password = Hash::make(Input::get('password'));
            $user->mobile   = Input::get('mobile');
            $user->role_id  = Input::get('role_id');

        // save our user
            $user->save();

Is this part of the code sufficient enough for my explanation? Or shoould I show you the entire code instead.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire