Home > Enterprise >  Division By Zero In Laravel in home.blade.php
Division By Zero In Laravel in home.blade.php

Time:01-08

I m having Division by Zero in home.blade.php. Is this due to PHP version or something wrong here as error showing

 <div id="student-view-slider" >
            <?php $__currentLoopData = $cors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
             <?php if($c->status == 1 && $c->featured == 1): ?>   
            <div >
                <div 
                    data-pt-placement="outside" data-pt-interactive="false"
                    data-pt-title="#prime-next-item-description-block<?php echo e($c->id); ?>">
                    <div >
                        <div >
                            <?php if($c['preview_image'] !== NULL && $c['preview_image'] !== ''): ?>
                            <a href="<?php echo e(route('user.course.show',['id' => $c->id, 'slug' => $c->slug ])); ?>"><img
                                    data-src="<?php echo e(asset('images/course/'.$c['preview_image'])); ?>" alt="course"
                                    ></a>
                            <?php else: ?>
                            <a href="<?php echo e(route('user.course.show',['id' => $c->id, 'slug' => $c->slug ])); ?>"><img
                                    data-src="<?php echo e(Avatar::create($c->title)->toBase64()); ?>" alt="course"
                                    ></a>
                            <?php endif; ?>
                        </div>
                        <div ><span>OFF<span><?php echo round((($c->price - $c->discount_price) * 100)

Screenshot of error

CodePudding user response:

You will need to make sure that $c->price is not equal to zero before trying to perform the division.

<?php 
if ($c->price != 0) {
    echo round((($c->price - $c->discount_price) * 100));
}
?>
  • Related