Skip to content

Eloquent Relationship With 3 joins #2577

@more-yogesh

Description

@more-yogesh

error

When I perform searching or sorting the above issue come across, Data rendering working properly.

When I work with two tables with the relationship all working fine. When I increase one more relationship the above error appears. Seems like eloquent with 3 tables are creating issues.

Controller

$meetings = Meeting::with(['user', 'contact', 'addedBy'])
            ->select(['meetings.*'])
            ->where(['user_id' => auth()->user()->id]);

        return DataTables::of($meetings)
            ->addIndexColumn()
            ->editColumn('status', function ($meetings) {
                return strtoupper($meetings->status);
            })
            ->editColumn('created_at', function ($meetings) {
                return [
                    'display' => e($meetings->created_at->format('d/M/Y H:i A')),
                    'timestamp' => $meetings->created_at->timestamp
                ];
            })
            ->filterColumn('created_at', function ($query, $keyword) {
                $query->whereRaw("DATE_FORMAT(created_at,'%m/%d/%Y') LIKE ?", ["%$keyword%"]);
            })
            ->addColumn('action', function ($meetings) {
                return $action = "<a href='" . route('contacts.edit', $meetings->id) . "' class='btn btn-info btn-sm' data-toggle='tooltip' data-placement='top' title='Edit Contact'><i class='fas fa-edit'></i></a>";
            })
            ->rawColumns(['action'])
            ->make(true);

Model

 public function contact()
    {
        return $this->belongsTo(Contact::class);
    }
    public function user()
    {
        return $this->belongsTo(User::class);
    }
    public function addedBy()
    {
        return $this->belongsTo(User::class, 'added_by');
    }

JSON Response

"data": [
{
"id": 1,
"contact_id": 305,
"user_id": 1,
"added_by": {},
"note": "",
"meeting_datetime": "2021-02-21 23:32:27",
"meeting_minutes": null,
"created_at": {},
"updated_at": "2021-02-20T20:27:46.000000Z",
"status": "CANCEL",
"user": {},
"contact": {},
"action": "<a href='http://localhost:8000/contacts/1/edit' class='btn btn-info btn-sm' data-toggle='tooltip' data-placement='top' title='Edit Contact'><i class='fas fa-edit'></i></a>",
"DT_RowIndex": 1
}
  • Windows 10
  • PHP 7.4
  • Laravel 8
  • Laravel-Datatables Version Latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions