vendredi 8 mai 2015

Laravel 4 how to merge database tables and order them by created_at?

I have 4 database tables that I want to merge together, and than I want to order all the data by created_at field. With my code all data is still grouped per database table, the result should be some sort of timeline of all my tables data. What am I doing wrong? It is only showing 4 items...

public function showIndex()
{

    $users = User::orderBy('created_at', 'desc')->get();
    $projects = Project::with('votes')->orderBy('created_at', 'desc')->get();
    $events = Calendar::orderBy('created_at', 'desc')->get();
    $jobs = Job::orderBy('created_at', 'desc')->get();

    $all = $users->merge($projects)->merge($events)->merge($jobs);

    return View::make('users.index')->with('events', $all);

}

Aucun commentaire:

Enregistrer un commentaire