我有问题用"和"传递两个变量。在Redirect :: route ...这是我的代码......
如何做到这一点
return Redirect::route('cart-success')->with(
array(
'cartSuccess' => 'You successfuly ordered. To track your order processing check your email',
'cartItems' => Cart::contents()
)
);
这是错误:
未定义的变量:cartItems(查看: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()
)
);
}
}
查看
@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
答案 0 :(得分:6)
你可以试试这个:
return Redirect::route('cart-success')
->with('cartSuccess', 'You successfuly ordered. To track your order processing check your email')
->with('cartItems', Cart::contents());
或者这个:
return Redirect::route('cart-success', array('cartSuccess' => '...', 'cartItems' => '...'));
答案 1 :(得分:0)
你可以传递两个这样的变量
$response=array('cartSuccess' => 'You have successfully ordered. To track your order processing check your email', 'cartItems' => Cart::contents());
return Redirect::route('cart-success',$response);
答案 2 :(得分:0)
您也可以使用它,这将有助于保持代码格式与通常的路由相同。
return \Redirect::route('your.route.name',['param1'=>'param1_value','param2'=>'param2_value']);