Support the ongoing development of Laravel.io →
Views Forms Architecture
Last updated 2 years ago.
0

Not possible. In Laravel 4, the View class is the view model, and you can only pass an array of attributes that are directly accessible inside the View's corresponding template as variables.

If you wanted to implement view models you would have to extend and replace the View\View and View\Environment classes at the very least.

Last updated 2 years ago.
0

How about passing a ViewModel class on the view lets say View::make('myview')->withModel($viewModel); where $viewModel is a class? will that benefit much?

Last updated 2 years ago.
0

You'd have to do $model->... for everything in your view, and there's nothing stopping another developer from adding variables outside the view model if he so wishes. I don't think it's worth it, you might as well just wrap your variables in presenter objects if you want to restrict what can be done in the view.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Daskul daskul Joined 22 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.