2014-10-20 122 views
0

嗨Iam使用laravel框架为我的应用程序我有单选按钮,即wdv & slm相应的值正在保存在数据库中,但我无法检索保存的值,同时编辑形成我想尽了各种办法,但我不能破解它,我知道我在做什么错了,请指导我解决这个问题..单选按钮不从laravel中的数据库检索旧值

我edit.blade.php

<!-- Depreciation Type --> 
      <div class="form-group {{ $errors->has('depreciation_type') ? ' has-error' : '' }}"> 
       <label for="depreciation_type" class="col-md-3 control-label depreciationlabel">@lang('admin/assetdetails/form.depreciation')</label> 
        <div class="controls col-md-7"> 
         {{ Form::radio('depreciation_type', 'wdv', Input::old('depreciation_type', $assetdetail->depreciation_type), array('id'=>'wdv', 'class'=>'wdvbutton')) }} 
         <label for="wdv" class="col-md-3 control-label wdvlabel">@lang('admin/assetdetails/form.wdv')</label> 
         {{ Form::radio('depreciation_type', 'slm', Input::old('depreciation_type', $assetdetail->depreciation_type), array('id'=>'slm','class'=>'wdvbutton')) }} 
         <label for="slm" class="col-md-3 control-label slmlabel">@lang('admin/assetdetails/form.slm')</label></br> 
         {{ $errors->first('depreciation_type', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }} 
        </div> 
      </div> 

控制器文件

public function getEdit($assetdetailId = null) 
    { 
     // Check if the location exists 
     if (is_null($assetdetail = Assetdetail::find($assetdetailId))) 
     { 
      // Redirect to the blogs management page 
      return Redirect::to('admin/settings/assetdetails')->with('error', Lang::get('admin/assetdetails/message.does_not_exist')); 
     } 
     $location_list = array('' => '') + Location::lists('name', 'id'); 
     $assettype_list = array('' => '') + Assettype::lists('asset_type', 'id'); 

     // Show the page 
     //$location_options = array('' => 'Top Level') + Location::lists('name', 'id'); 

     $assetdetail_options = array('' => 'Top Level') + DB::table('asset_details')->where('id', '!=', $assetdetailId)->lists('asset_number', 'id'); 
     return View::make('backend/assetdetails/edit', compact('assetdetail'))->with('assetdetail_options',$assetdetail_options)->with('location_list',$location_list)->with('assettype_list',$assettype_list); 
    } 


    /** 
    * Location update form processing page. 
    * 
    * @param int $locationId 
    * @return Redirect 
    */ 
    public function postEdit($assetdetailId = null) 
    { 
     // Check if the location exists 
     if (is_null($assetdetail = Assetdetail::find($assetdetailId))) 
     { 
      // Redirect to the blogs management page 
      return Redirect::to('admin/settings/assetdetails')->with('error', Lang::get('admin/assetdetails/message.does_not_exist')); 
     } 



     // get the POST data 
     $new = Input::all(); 


     // attempt validation 
     if ($assetdetail->validate($new)) 
     { 

      // Update the location data 

      $assetdetail ->asset_number    = e(Input::get('asset_number')); 
      $assetdetail ->location_id    = e(Input::get('location_id')); 
      $assetdetail ->assign_to    = e(Input::get('assign_to')); 
      $assetdetail ->asset_type_id   = e(Input::get('asset_type_id')); 
      $assetdetail ->nesd      = e(Input::get('nesd')); 
      $assetdetail ->active     = e(Input::get('active')); 
      $assetdetail ->shift     = e(Input::get('shift')); 
      $assetdetail ->supplier_name   = e(Input::get('supplier_name')); 
      $assetdetail ->description    = e(Input::get('description')); 
      $assetdetail ->dateof_purchase   = e(Input::get('dateof_purchase')); 
      $assetdetail ->label_number    = e(Input::get('label_number')); 
      $assetdetail ->purchase_price   = e(Input::get('purchase_price')); 
      $assetdetail ->dateof_disposed   = e(Input::get('dateof_disposed')); 
      $assetdetail ->depreciation_type  = e(Input::get('depreciation_type')); 
      $assetdetail ->salvage_value   = e(Input::get('salvage_value')); 
      $assetdetail ->asset_life    = e(Input::get('asset_life')); 




      // Was the asset created? 
      if($assetdetail->save()) 
      { 
       // Redirect to the saved location page 
       return Redirect::to("admin/settings/assetdetails/$assetdetailId/edit")->with('success', Lang::get('admin/assetdetails/message.update.success')); 
      } 
     } 
     else 
     { 
      // failure 
      $errors = $assetdetail->errors(); 
      return Redirect::back()->withInput()->withErrors($errors); 
     } 

     // Redirect to the location management page 
     return Redirect::to("admin/settings/assetdetails/$assetdetailId/edit")->with('error', Lang::get('admin/assetdetails/message.update.error')); 

    } 

注:我使用VARCHAR作为我的数据类型在数据库中保存我的单选按钮值WDV & SLM

我试图

{{ Form::radio('depriciation_type', 'wdv', (Input::old('depriciation_type') == 'wdv'), array('id'=>'wdv', 'class'=>'radio')) }} 
{{ Form::radio('depriciation_type', 'slm', (Input::old('depriciation_type') == 'slm'), array('id'=>'slm', 'class'=>'radio')) }} 

我也试过

<input type="radio" name="type" value="wdv" class="radio" id="wdv" <?php if(Input::old('type')== "wdv") { echo 'checked="checked"'; } ?> > 
<input type="radio" name="type" value="slm" class="radio" id="slm" <?php if(Input::old('type')== "slm") { echo 'checked="checked"'; } ?> > 

我是否需要在路由文件中添加任何内容。

请帮我解决这个问题..提前感谢。

+0

的可能重复[Laravel 4 - 输入::老单选按钮(http://stackoverflow.com/questions/17059244/laravel- 4-inputold-for-radio-buttons) – Jerodev 2014-10-20 11:04:16

+0

@Jerodev谢谢你的回复我已经试过了,你可以在上面看到我的帖子,如果有什么不对的地方请告诉我(看我也试过) – megamage 2014-10-20 11:06:39

+0

@Jerodev是还有什么我能做的,而不是为了得到这项工作。 – megamage 2014-10-20 11:12:06

回答

3

,我发现自己的答案,这是我做了什么

{{ Form::radio('depreciation_type', 'wdv', Input::old('depreciation_type', $assetdetail->depreciation_type == 'wdv'), array('id'=>'wdv', 'class'=>'wdvbutton')) }} 
{{ Form::radio('depreciation_type', 'slm', Input::old('depreciation_type', $assetdetail->depreciation_type == 'slm'), array('id'=>'slm', 'class'=>'slmbutton')) }} 
相关问题