mercredi 1 juillet 2015

Laravel 5: Unable to pass data to controller via redirect

I am trying to pass a query builder to view and I want to print it. Query builder does not return null, but I am unable to pass it or print it.

Controller

public function search() {
    $option1 = Request::get( 'option1' );
    $option2 = Request::get( 'option2' );
    $condition = Request::get( 'condition' );
    $date_option = Request::get( 'dateOption' );
    $option1_value = Request::get( 'option1_value' );
    $option2_value = Request::get( 'option2_value' );
    $fromDate = Request::get( 'fromDate' );
    $toDate = Request::get( 'toDate' );

    if ( $condition == 'no' ) {
        $vehicles = Vehicle::with( 'brand', 'section', 'representive', 'buyer', 'seller', 'buyingPaymentType', 'sellingPaymentType' )->where( $option1, $option1_value )->get();
        //return $vehicle;
    }
    if ( $condition == 'or' ) {
        $vehicles = Vehicle::with( 'brand', 'section', 'representive', 'buyer', 'seller', 'buyingPaymentType', 'sellingPaymentType' )->where( $option1, $option1_value )->orWhere( $option2, $option2_value )->get();
    }
    if ( $condition == 'and' ) {
        $vehicles = Vehicle::with( 'brand', 'section', 'representive', 'buyer', 'seller', 'buyingPaymentType', 'sellingPaymentType' )->where( $option1, $option1_value )->where( $option2, $option2_value )->get();
    }

    return  redirect()->back()->with( 'vehicles', $vehicles );
    //return $vehicles;
}

View

@if(isset($vehicles))
    @foreach($vehicles as $vehicle)
        <td>{{ $vehicle->id }}</td>
    @endforeach
@endif

What am I doing wrong? Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire