Categories
Uncategorized

Patterns That Pay Off

Notes from Matt Stauffer’s talk.


/*
View Model
*/
class DashboardViewModel
{
    function topTasks()
    {
        $overdue = $this->overDueTasks();
        return array_merge($overdue, $this->fillTasksDueSoon( count($overdue) ));
    }

    function progressChart()
    {
        return [
            'complete' => $this->progressDone(),
            'date_markers' => $this->dateMarkers()
        ];
    }

}

return view('dashboard')->with('vm', new DashboardViewModel($user));

?>

View Data Composition

Presenter
    Layer above other thing, usually the model, to give it more powers.

View Model
    PHP Object for organizing this logic 

Responsable (sic)
    interface in Laravel for PHP object that can be converted to Response 

View Models

These seem fairly easy to understand. A class that wraps a model, providing methods for data access that a view will need. Moves the complexity of querying out of Controller.

And nicer than putting straight on model which complicates it in a lot of unrelated contexts.