Home > OS >  undefined variable error when updating a script in laravel
undefined variable error when updating a script in laravel

Time:11-30

am encounering a certain error here,i want to get some data from the shipping charges table in the method at the controller,after defining the variable in the method and having all the data defined , one of the scripts stops working but when i remove the code the script works perfectly.i still need to use the code because there's some data i want to fetch from the table and pass it to the blade file..where might i have gone wrong with my code.,i have tried to debug using the network section and the error responds that the error is in the blade file undefined variable $shippingcharges have a look below

the part in the blade file which gives out the error

     <!-- County of the Buyer-->
        <div class="form-group">
            <label class="control-label" for="county">Your County
            </label>
            <select name="countyname" class="form-control" id="FormControlSelect">
                <option>Select Your County</option>
                @foreach($shippingcharges as $shippingcharge)
                   <option value="{{ $shippingcharge->id }}">{{ $shippingcharge->county }}</option>
                @endforeach
            </select>
        </div>

the function in the controller

public function cart()
   {
        $events=Events::latest()->take(4)->get();
        $shippingcharges=shipping_charge::where('is_shipping',1)->get();
        $usercartitems=Cart::usercartitems();
        return view('frontend.product.cart')->with(compact('usercartitems','shippingcharges','events'));
   }

CodePudding user response:

This error is occurring because the variable '$shippingcharges' is present in blade and controller not passing this variable to the blade. post your controller, blade and script

  • Related