What is: Controller

A controller is part of the MVC (Model – View – Controller) design pattern. The model manages the data, logic and rules of the application. The view renders the visual layout for the user, these are basically templates. The controller accepts user requests, interacts with the model and selects the view for response.

Here is an example code from Laravel. The user requests a post, the controller loads it from database and returns a view with post content.

Route::get('post/{id}', function($id) { // Controller

    $post = Post::where('id', $id)->first(); // Model

    return view('posts.show')->with('post', $post); // View

});

Recent articles

loading
×