I have problem to pass two varialbles with "with" in Redirect::route... Here is my code...
How to do this
return Redirect::route('cart-success')->with(
array(
'cartSuccess' => 'You successfuly ordered. To track your order processing check your email',
'cartItems' => Cart::contents()
)
);
Here is error:
Undefined variable: cartItems (View: C:\xampp\htdocs\laravel-webshop\laravel\app\views\cart-success.blade.php)
Route::group(array('before' => 'csrf'), function() {
//Checkout user POST
Route::post('/co-user', array(
'as' => 'co-user-post',
'uses' => 'CartController@postCoUser'
));
});
CONTROLLER
public function postCoUser() {
$validator = Validator::make(Input::all(), array(
'cardholdername' => 'required',
'cardnumber' => 'required|min:16|max:16',
'cvv' => 'required|min:3'
));
if($validator->fails()) {
return Redirect::route('checkout')
->withErrors($validator)
->withInput();
} else {
return Redirect::route('cart-success')->with(
array(
'cartSuccess' => 'You successfuly ordered. To track your order processing check your email',
'cartItems' => Cart::contents()
)
);
}
}
View
@extends('publicLayout.main')
@section('content')
@if(Session::has('cartSuccess'))
<p>{{ Session::get('cartSuccess') }}</p>
<?php $total = 0; ?>
@foreach ($cartItems as $cartItem)
Name: {{ $cartItem->name }} <br>
Price: {{ $cartItem->price }} €<br>
Quantity: {{ $cartItem->quantity }} <br>
<?php $final = $cartItem->price * $cartItem->quantity; ?>
Final price: {{ $final }} €<br>
<?php $total += $final; ?>
<hr>
@endforeach
Total: {{ $total }} €
@endif
@stop
Redirect::with()
set the session variable, not setting your view variable. Where is the method defined in routecart-success
? From there you'll have to retrieve the session value and pass the value to your view usingView::make()
– JofryHSroute('cart-success')
going? Can you post the code to that route as well (the controller method)? – JofryHScart-success
is? You are only showing your POST route, not the route after the submission (success route) – JofryHS