LaravelShoppingcart
LaravelShoppingcart copied to clipboard
I HAVE A LITTLE SHOPPINGCART PROBLEM ON INVALID PRICE
In my CartContoller i have this code
public function store(Request $request) {
Cart::add($request->id, $request->name, 1, $request->price)
->associate(App\Product);
return redirect()->route('cart.index')->with('success_message', 'Item Added to cart successfully');
}
and in my Model i have this code:
public function presentPrice(){
return $ . number_format($this->price, 2);
}
but i am getting error message. Please supply a valid price.
someone help me out here
hello, please:
1- create the Helper in your App Directory and make this function
function presentPrice($price)
{
$price2 = str_replace (',', '.', str_replace ('.', '', $price)) / 100;
;
return number_format($price2, 2,',', '.');
}
2- reference for your composer.json on file
"autoload": {
"files": [
"app/helpers.php"
],
3 - composer dump-autoload
4 - In your views references your objects into functions presentPrice( ):
{{ presentPrice($product->price) }}
5 - my language is pt_BR, adapte to language points.
Check your price value in the controller, probably it is not passed correctly.