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.