2017-04-08 10 views
1

は私がオプション値デフォルト

<div class="form-group"> 
    <label for="theme" class="col-sm-3 control-label">Theme</label> 
    <select class="form-control" id="theme" name="theme"> 
     <option value="0">Default Theme</option> 
     <option value="1">Dark Theme</option> 
    </select> 
</div> 

、私のコントローラで、私はそれ、ユーザが選択したどのようなスタイルにとてもオプション選択値のデフォルトは作ることができる方法

/** 
* Change User Account Settings 
* 
* @access public 
* @return view user.settings 
*/ 
public function changeSettings($username, $id) 
{ 
    $user = Auth::user(); 
    if (Request::isMethod('post')) { 
     $user->style = (int) Request::get('theme'); 
     $user->save(); 
    return Redirect::route('profil', ['username' => $user->username, 'id' => $user->id])->with(Toastr::success('Your Account Was Updated Successfully!', 'Yay!', ['options'])); 
    } else { 
     return redirect()->back()->with(Toastr::warning('Something Went Wrong!', 'Error', ['options'])); 
    } 
} 

、私の見解では、このビットを持っていますDBに?あなたのビューで

答えて

0

、あなたがそうのようにそれを作る:

<option value="0" @if($selectedTheme == 0) SELECTED @endif>Default Theme</option> 
<option value="1" @if($selectedTheme == 1) SELECTED @endif>Some other theme Theme</option> 

(。もちろん、あなたのコントローラによって返されているものに$selectedThemeを変更)

+1

おかげで完全に働きました –

関連する問題