vendredi 23 octobre 2015

Laravel pass db data from controller to the view

The problem is that I cant pass the db result to the view. If I debug it on Controller side everything is ok, so db query is working fine, but when I try to get the variable in view it says that variable is not defined. Controller:

$records = DB::table('records')
        ->join('call_charges', function($join)
        {
            $join->on('records.inbound_originating_address_region', '=', 'call_charges.RateDestination')
                ->on('records.inbound_originating_address_type', '=', 'call_charges.RateType');
        })
        ->join('phone_types', 'records.inbound_originating_address_type', '=', 'phone_types.phone_type_id')
        ->orderBy('records.inbound_initiated_utc', 'asc')
        ->get();
return View::make( 'records.index' )->with( 'records', $records );

View:

@extends('app')

@section('content')

    @if (Auth::check())

    <h2>Call records</h2>

        @if ( !$records->count() )
            No call records to view!
        @else
            <table class="table table-striped table-hover table-condensed table-bordered">
                <thead>
                <tr>
                    <th>Time</th>
                    <th>Out call</th>
                    <th>Duration</th>
                    <th>Cost</th>
                    <th>Billable</th>
                    <th>Country</th>
                    <th>Type</th>
                    <th>Caller</th>
                    <th>Receiver</th>
                </tr>
                </thead>
                <tbody>
                @foreach( $records as $record )
                    <tr>
                    <td>{{ $record->inbound_initiated_utc }}</td>
                    @if ( $record->is_in_call == 1 )
                    <td class="success">Yes</td>
                    @else
                    <td class="warning">No</td>
                    @endif
                    <td>{{ $record->inbound_duration }}</td>
                    <td>{{ $record->session_total_charges }}</td>
                    <td>0</td>
                    <td>{{ $record->inbound_originating_address_region }}</td>
                    <td>{{ $record->inbound_originating_address_type }}</td>
                    <td>{{ $record->inbound_originating_address }}</td>
                    <td>{{ $record->inbound_destination_address }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif

    @endif

    @unless (Auth::check())
        You are not signed in. Please sign in <a href='/auth/login'>here</a>
    @endunless
@endsection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire