drfcaw7460 2014-10-20 10:57
浏览 34
已采纳

单选按钮不在laravel中从数据库中检索旧值

Hi Iam using laravel framework for my application i have radio buttons namely wdv & slm the corresponding values are getting saved in database but i am not able to retrive the saved value while editing the form i tried different solutions but i couldn't crack it,i do know what am i doing wrong please guide me to solve this issue..

My 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>

Controller file

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'));

    }

Note:I am using varchar as my datatype to save my radio button values in database as wdv & slm

I tried

{{ 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')) }}

I also tried

<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"'; } ?> >

Should i need to add anything in route file.

Please help me to solve this issue..Thanks in advance.

  • 写回答

1条回答 默认 最新

  • drze7794 2014-10-23 10:10
    关注

    I found the answer myself this is what i did

    {{ 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')) }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?