I have products table that has 2 columns price_before | price_after
In the view I loop through all products
@foreach($products as $product)
{{$product->price_before}}
{{$product->price_after}}
@endforeach
I would like to get the percentage and achieve an equation like
(1 - New Price / Old Price)*100)
so that it looks 50% or at least 50 .. not like 50.1234223
my ProductsController.php
public function index(){
$products = Product::orderBy('created_at','desc')->paginate(39);
return view('products', ['products' => $products]);
}
How can I achieve that in the productscontroller ?