Check Here
Check Here

What is view model package ? How does it work ? How to use it ?


The laravel view model is a laravel package created by Brent Roose. This package can move the work into a “view model” that you might do inside a controller. The main objective of this view model is that it is designed to house the complex logic of your views and clean up view-related logic from controllers.

For instance: Have you ever made a controller where you had to do a lot of work to prepare variables to be passed to a view? You can move that kind of work to a so-called view model. In essence, view models are simple classes that take some data and transform it into something usable for the view.

How does it work ?

Create a  postViewModel class extending the main ViewModel class.

Now, the above class will get credited in to your controller.

They altogether (Model view and Controller) provide your view with the following abilities.

This package acts as the abstraction to the logic of your view.
How ?
Well, instead of passing the view model to the view, you can return a view directly like this.

Also, the function which requires extra parameters can be exposed

Which you can then reference in your template:


Github Repository:
Laravel News:

. . .


Add Your Comment

Be the first to comment.

Bagisto helped us in creating this full functional, professional and user friendly web app. Bagisto has lot to offer to the developer and the user. The framework is outstanding.

Yosseph Baruch Dolgopolsky

Yosseph Baruch Dolgopolsky
Talk to Sales


Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home