首页 > 解决方案 > Laravel 刀片表到 AJAX

问题描述

嗨,我有很多收据和合作伙伴的用户。我需要一张这样的桌子。

ID | Receipt Number | Username | Receipt Date | Partner name| Partner Phone |  Operations

这是我的控制器。用户与收据合作伙伴有关系,他们返回我需要的结果。

 public function index()
{

    $user = Auth::id();
     $datas = Operation::with('user','receipt', 'partner')->where('user_id', $user)->get();
    return view('operations.index', compact('datas'));

}

这是视图

<table class="datatables-basic table" id="example">
    <thead>
    <tr>
        <th>#</th>
        <th></th>
        <th>User</th>
        <th>Date</th>
        <th>Partner</th>
        <th>Phone</th>
        <th>Amallar</th>
    </tr>
    </thead>
    <tbody>
    @foreach($datas as $idx => $data)
        <tr>
            <td>{{$idx+1}}</td>
            <td>{{$data->receipt->number}}</td>
            <td>{{$data->user->username}}</td>
            <td>{{$data->receipt->date}}</td>
            <td>{{$data->partner->username}}</td>
            <td>{{$data->partner->phone}}</td>
            <td>
                <a href="#" class="btn btn-icon btn-flat-primary">
                    <i class="fas fa-edit"></i>
                    Edit
                </a>
                <a href="#" class="btn btn-icon btn-flat-primary">
                    <i class="fas fa-view"></i>
                    View
                </a>

                <a href="#" class="btn btn-icon btn-flat-primary">
                    <i class="fas fa-trash"></i>
                    Delete
                </a>
            </td>
        </tr>
    @endforeach
    </tbody>
</table>

问题是{{$data->receipt->number}},,{{$data->receipt->date}}{{$data->partner->username}}“此集合中不存在属性 [日期]”。

第二个问题如何将此表转换为 AJAX?

这是操作表

id| user_id | parner_id | receipt_id | date | amount | price

这是收据表

id | date | type | user_id

谢谢

标签: ajaxlaraveleloquent

解决方案


推荐阅读