Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

riaanv1987's avatar

Multiple query results not merging

HI there I have a table that I run a query on to get all the users records in the table and then I return a datatable with the data. This works 100%. My problem is I need to add data to this datatable from another table in the db as well currently I have tried the following but I just get a datatable error. Both tables structure is the same. And I just can't get the table to display the information of both tables.

public function kryAandele()
{
    $user = Auth::user();
    $share = $user->shares()->where('status_id',3)->get();
    $alternates = $user->alternates()->where('status_id', 3)->get();
    $shares = $share->merge($alternates);
    return DataTables::of($shares)->editColumn('created_at', function (Share $share){
        return $share->created_at->toDateString();
    })->editColumn('status_id', function (Share $share){
        return $share->status->name;
    })->editColumn('sert_nommer', function (Share $share){
        return strval($share->sert_nommer);
    })->toJson();
}
0 likes
1 reply
riaanv1987's avatar
riaanv1987
OP
Best Answer
Level 1

Fixed my own problem heheh thanks anyhow.

public function kryAandele()
{
    $user = Auth::user();
    $share = $user->shares()->where('status_id', 3)->get();
    $alternates = $user->alternates()->where('status_id', 3)->get();
    $shares = $share->merge($alternates);
    return DataTables::of($shares)->editColumn('created_at', function ($shares){
        return $shares->created_at->toDateString();
    })->editColumn('status_id', function ($shares){
        return $shares->status->name;
    })->editColumn('sert_nommer', function ($shares){
        return strval($shares->sert_nommer);
    })->toJson();
}

Please or to participate in this conversation.