У меня есть проблема передать два varialbles с «with» в 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' )); });
КОНТРОЛЛЕР
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
Вы можете попробовать следующее:
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' => '...'));
Вы можете передать две переменные
$response=array('cartSuccess' => 'You have successfully ordered. To track your order processing check your email', 'cartItems' => Cart::contents()); return Redirect::route('cart-success',$response);