irankhosravi
3 months ago
53
14
Laravel

How to show multiple table in a blade?

Posted 3 months ago by irankhosravi

I have 2 tables orders and order_mobiles in my database. I want to show this 2 tables in my blade.

ReportController.php

public function index() {
    $orders = Order::latest()->where('status', '=', '1')->paginate(50);
    $order_mobiles = OrderMobile::latest()->where('status', '=', '1')->paginate(50);
    return view('Admin.orders.index', compact('orders', 'order_mobiles'));
}

index.blade.php

      @foreach ($orders as $order)
            @foreach ($order_mobiles as $order_mobile)
                <tr>
                    <td>
                        <a href="{{ route('reports.show', $report) }}">
                            {{ $order->name }}
                            {{ $order_mobile->name }}
                        </a>
                    </td>
                    <td>{{ $order->first_name }} {{ $order->last_name }}
                    {{ $order_mobile->first_name }} {{ $order_mobile->last_name }}
                    </td>
                    <td>{{ $order->expert_name }}{{ $order_mobile->expert_name }}</td>
                    <td>{{ $order->received_money }}{{ $order_mobile->received_money }}</td>
                    <td>{{ $order->issue_number }}{{ $order_mobile->issue_number }}</td>
                    <td>{{ jdate($order->update_at)->format('%T') }}{{ jdate($order_mobile->update_at)->format('%T') }}</td>
                </tr>
            @endforeach
      @endforeach

I see and It show bad. What is the best way to display 2 tables?

Please sign in or create an account to participate in this conversation.