ViewModel for contact form in Laravel

I am not new to MVC but I am just getting started with Laravel. In ASP.NET MVC, we have ViewModels, which is basically a data object that we can pass to a View. The view can then use the ViewModel in any way it wishes.

Is there such a thing in Laravel? I want to create a ViewModel that I can pass to my contact view and create a scaffold view around it!

I currently have:

ROUTE

Route::get('/contact', array('as' => 'contact', 'uses' => 'HomeController@contact'));

Route::post('/contact', array('as' => 'contact', 'uses' => 'HomeController@postContact'));

      

CONTROLLER

<?php

class HomeController extends BaseController {

    public function contact()
    {
        return View::make('contact');
    }

    public function postContact()
    {
        $formData = Input::all();

        return View::make('contact');
    }

}

      

Also, do you foresee something wrong with my routes and controller code? In ASP.NET MVC, we can have a route with the same name as long as the verbs are different (POST / GET).

My contact form has 3 text boxes (name, email and subject) and one text box (message).

+3


source to share


1 answer


You are probably talking about view/model presenter

, which is another layer between yours model

and view

, in which case you can create your own or use existing packages:



Also read this article to get a clear understanding of presenter

.

0


source







All Articles