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 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数