dimanche 17 mars 2019

Laravel Blade return null values to controller

I am trying to get form text field enter values from blade to controller variable and then pass in to db query but it gives me null values.

For example, $a = request('chargeable_price');

this give me null value. Can some one help me? Code run without error but database field update as zero without passing value.

This is my controller code

public function postEditSubscription(Request $request, $property_id, $subscription_id){


        try {

            $a = request('chargeable_price');

            DB::table('subscriptions')->where('id',$subscription_id)->update(array(
                'price'=>$a,
            ));


        }catch(ModelNotFoundException $e){

            throw $e;

        }catch(ModelValidationException $e){


            throw $e;

        }catch(IntegrityException $e){

            throw $e;

        }catch(Exception $e){


            throw $e;

        }

      //  $request->flush();

        return redirect()->route('admin::managing::subscription::index', array('property_id' =>$property_id))->with(Sess::getKey('success'), Translator::transSmart('app.You have successfully edit Subscription Details.', 'You have successfully edit Subscription Details.'));


    }

This is my blade code

@section('content')

    <div class="admin-managing-subscription-invoice">

        <div class="row">

            <div class="col-sm-12">
                <div class="page-header">
                    <h3>
                        
                    </h3>
                </div>
            </div>
        </div>




        <div class="row">
            <div class="col-sm-12">

                

                <form class="form-horizontal booking-form" method="post" action="">
                    


                    @php
                    $reservedPeriodDetails = array(
                        'reserved_days' => $subscription->getReservedDays(),
                        'days_in_calendar_month_by_current_reserved_period' => $subscription->getDaysInCalendarMonthByCurrentReservedPeriod()
                    );
                @endphp
                <div class="hide reserved-period" data-details=""></div>
                <div class="row">
                    <div class="form-group">
                        <?php
                        $field = 'start_date';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Subscription Date', 'Subscription Date');
                        $start_date = old('start_date', $subscription_table->start_date);
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-4 input-group schedule">
                            
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        $field2 = 'end_date';
                        $name2 = sprintf('%s[%s]', $subscription->getTable(), $field2);
                        $translate2 = Translator::transSmart('app.Subscription End Date', 'Subscription End Date');
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-4 input-group schedule">
                            
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        $field = 'name';
                        $name = sprintf('%s[%s]', $package->getTable(), $field);
                        $translate = Translator::transSmart('app.Package Name', 'Package Name');
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            <p class="form-control-static"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <?php
                        $field = 'category_name';
                        $name = sprintf('%s[%s]', $package->getTable(), $field);
                        $translate = Translator::transSmart('app.Package Category', 'Package Category');
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            <p class="form-control-static"></p>
                        </div>
                    </div>

                    <div class="form-group required">
                        <?php
                        $field = 'contract_month';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Contract Month', 'Contract Month');
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            @php
                                $contract_months = [];
                                for($i = 1; $i <= 24; $i++){
                                    $contract_months[$i] = $i;
                                }
                                $contract_month = (old('contract_month', $subscription_table->contract_month)) - 1;
                                $default_month = $contract_month;
                                if(\Request::get('subscriptions') !== null && \Request::get('subscriptions')['contract_month'] > 0){
                            $default_month = \Request::get('subscriptions')['contract_month'];
                        }
                            @endphp
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        $field = 'price';
                        $name = sprintf('%s[][price]', $subscription_month_price->getTable());
                        $translate = Translator::transSmart('app.Regular Price', 'Regular Price');
                        ?>
                        <label for="" class="col-sm-2 control-label">
                            <div>
                                
                            </div>
                            <div>
                                
                            </div>
                        </label>
                        <div class="col-sm-10 prices">
                            @php
                                $contract_month = (old('contract_month', $subscription_table->contract_month) - 1);
                                    $default_month = $contract_month;
                                    if($subscription->contract_month > 0){
                                        $default_month = $subscription->contract_month;
                                    }
                            @endphp

                            @for ($i = 0; $i < $default_month; $i++)

                                @php
                                    $name = sprintf('%s[%d][price]', $subscription_month_price->getTable(), $i);
                                   // $default_price = old('subscription_month_price.'.$i.'.price', $subscription->getAttribute($field));
                                    $default_price = old('.price', $subscription_month_price_table->price.$i);

                                     // $deposit = old('deposit', $subscription_table->deposit);

                                 //   if($i == 0){
                                  //      $default_price = old('subscription_month_price.'.$i.'.price', $subscription->getAttribute('pro_rate_price'));
                                   // }
                                @endphp
                                <div class='month-price-row'>
                                    <p class="form-control-static">Month: </p>
                                    <div class="input-group">
                                        <span class="input-group-addon"></span>
                                        
                                    </div>
                                </div>

                            @endfor


                        </div>
                    </div>

                    <div class="form-group required">
                        <?php
                        $field = 'seat';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Seat', 'Seat');
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            
                        </div>
                    </div>

                    <div class="form-group required">
                        <?php
                        $field = 'deposit';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Deposit', 'Deposit');
                        $translate1 = Translator::transSmart('app.Only allow this format "#.##".', 'Only allow this format "#.##".');
                        $deposit = old('deposit', $subscription_table->deposit);
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12">
                            <hr />
                            <h3>
                                
                            </h3>
                            <hr />
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        $field = 'chargeable_price';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Package', 'Package');
                        ?>
                        <label for="" class="col-sm-2 control-label">
                            
                            <a href="javascript:void(0);" class='help-box' data-container="body" data-toggle="popover" data-trigger="focus"  data-placement="top" data-html="true" data-content="">
                                <i class="fa fa-question-circle fa-lg"></i>
                            </a>
                        </label>
                        <div class="col-sm-10">
                            
                            <div class="input-group">
                                <span class="input-group-addon"></span>
                                
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        $field = 'tax';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);print_r($property->is_taxable);
                        $tax_value = (($property->is_taxable == true)?$property->tax_value:0);
                        $translate = Translator::transSmart('app.Tax (%s)', sprintf('Tax (%s)', CLDR::showTax($tax_value)), true, ['tax' => CLDR::showTax($tax_value)])
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            <div class="input-group">
                                <span class="input-group-addon"></span>
                                
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <?php
                        $field = 'deposit';
                        $field1 = 'gross_deposit';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field1);
                        $translate = Translator::transSmart('app.Deposit', 'Deposit');
                        $deposit = old('deposit', $subscription_table->deposit);
                        ?>
                        <label for="" class="col-sm-2 control-label">
                            
                            <a href="javascript:void(0);" class='help-box' data-container="body" data-toggle="popover" data-trigger="focus"  data-placement="top" data-html="true" data-content="">
                                <i class="fa fa-question-circle fa-lg"></i>
                            </a>
                        </label>
                        <div class="col-sm-10">
                            
                            <div class="input-group">
                                <span class="input-group-addon"></span>
                                
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <?php
                        $field = 'gross_price_and_deposit';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Gross Total', 'Gross Total');
                        ?>
                        <label for="" class="col-sm-2 control-label">
                            
                            <a href="javascript:void(0);" class='help-box' data-container="body" data-toggle="popover" data-trigger="focus"  data-placement="top" data-html="true" data-content="">
                                <i class="fa fa-question-circle fa-lg"></i>
                            </a>
                        </label>
                        <div class="col-sm-10">
                            
                            <div class="input-group">
                                <span class="input-group-addon"></span>
                                
                            </div>
                        </div>
                    </div>

                    <div class="form-group required">
                        <?php
                        $field = 'user_id';
                        $name = sprintf('%s[%s]',  $subscription_user->getTable(), $field);
                        $name1 = sprintf('%s[%s]', 'typeahead', $field);
                        $translate = Translator::transSmart('app.Member', 'Member');
                        $member_name = old('full_name', $users_table->full_name);
                        $route = URL::route('admin::managing::member::subscription-package', array('property_id' => $property->getKey(), 'package_id' => $package->getKey()));

                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            
                            <div class="twitter-typeahead-container">
                                
                            </div>
                        </div>
                    </div>
                    <div class="form-group required">
                        <?php
                        $field = 'company_id';
                        $name = sprintf('%s[%s]', $subscription->getTable(), $field);
                        $translate = Translator::transSmart('app.Company', 'Company');
                        $company_Name = old('name', $company->name);
                        ?>
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            
                            
                            <a href="javascript:void(0);" class="add-company" data-url="" style="float:right;margin-bottom: 5px;">
                                
                            </a>
                            <div style="clear:both;"></div>
                            <div class="twitter-typeahead-container">
                                
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">

                            <div class="btn-group">


                                



                            </div>
                            <div class="btn-group">
                                @if(isset($is_from_lead) && $is_from_lead)
                                    <a href="javascript:void(0);"
                                       title = ""
                                       class="btn btn-theme btn-block cancel payment-utility-cancel" onclick = "widget.popup.close(false, null, 0)" >
                                        
                                    </a>
                                @else
                                    
                                @endif
                            </div>
                        </div>
                    </div>





                </div>

                </form>


            </div>



        </div>
    </div>





    </div>

@endsection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire