Support the ongoing development of Laravel.io →
Input Views Architecture

Hi Guys,

I am Pretty New To Developing in PHP + Laravel, I was recently learning to Code Raw PHP when I decided to Invest in Laravel after reading up on it... I have made some head way in understanding the Routes and Blades etc... and so forth... However While I somewhat understand MVC I am not 100% clear on it...

From what I have read this is how I interpret it and ask if you would take the time to correct me where I stray of the MVC Path...

First in Understanding the Model, I understand that one creates a Model per Table in the Database, Inside the Model one will define the Functions that Retrieve the Data from the model in Defined methods

For Example: 
	
	we have a table (Users)
	
	so we will create several methods which can be called to get data from the table in controlled ways
		- function All_Users ();
			- This will return all users from the table
		- function get_Users ($id);
			- This will return users based on the parameter defined $id
	

We can Create several functions which will be called from the controller to get the data in several different ways. Including Removing Information etc.
	- Like top_ten(), last_entry() etc as required by website... and so on etc.

Second is the Controller, The Controller which is called from the view will then have its CRUD operations or Several Variations of specific CRUD operations that will call on the methods defined in the model as follows

For Example:
	Using the Model Above we will call the model then its method All_Users () as follows
		$Users->All_Users();
		
	This will simply Get the data from the model as predefined in the model
	
As I understand it the Controller is there to communicate between a view and 1 or more models...
	Meaning in the case that I had a dashboard and wanted to see the users with the roles and the Permissions I would have a dashboard controller that 
	makes calls to the models
		* Users
		* Roles
		* Permissions
		
	Then it will pass the information back to the Dashboard view and the view will manipulate the Data and present it in the desired format and design.
	
	The Controller should be as light as possible so it should not manipulate the data which should be the task of the model and should just be passing 
	requests from the view to the model and the data back to the view from the model
	
	The Controller will have CRUD Methods which will simply define what Models and Methods of the Models should be executed to get the results it needs
	and then the results are passed back to the view to be displayed.
	
(From My Novice Point of View I would create a Controller Per View in the Case where the particular View needs to communicate with the database)

Third is the View, The View is what the user sees, It makes any requests from user input and processes it by making the relevant calls to the Controller and then or any request without user input manipulates it to present the results to the user to see...

The View never connects directly to the data or the model and always goes via the Controller...

Please provide me with any clarity if my understanding it incorrect... As I am new to MVC, I have been reading about it for some time but this is the first time I am using it. I have read a few books as well but most people who write about MVC or any other assume that anyone who is programming has used it in some form or another before... And this is not the case... I can easily learn it as i go along but if it don't understand it correctly I might become accustomed to using it the wrong way and then it will be hard to change those ways later on.

Last updated 3 years ago.
0

It's a tricky one to explain in a forum. You have the basic gist...

Model In Laravel, you would generally use the model for 'getting' or 'setting' data. Known as Accessors and Mutators. The model is also the place where you would define relationships with other models. There is more to it than that, but I'll leave it there so not to confuse things.

Controller Controls the data flow. This can include your queries to the databse and also incorporate the Accessor/Mutator data from earlier. The controller is basically the boss that tells the view what to show and what the model should store.

View This the easy one. Just displays the data that has been passed to it from the controller. If you have forms etc, then when you submit it, you would pass this info to the controller that then handles what to do with it - store it in the db, fire off an email etc.

There are a load great tutorials at http://laracasts.com - worth checking out. The more you watch, the more things will sink in. There is nothing like getting stuck in with a dummy project. I found this useful anyway. I read and read, watched video after video and it is only when I got stuck into it, that it stuck. Sure you will mess up along the way, but you'll learn quickly.

Hope it helps.

Last updated 3 years ago.
0

I just want to share you this tutorial. Complete Laravel Ajax CRUD operation with Search, Sort, and pagination https://laracast.blogspot.com/2016/06/laravel-ajax-crud-search-sort-and.html

0

Sign in to participate in this thread!

Eventy

Your banner here too?

XenitXTD xenitxtd Joined 15 Oct 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.

© 2025 Laravel.io - All rights reserved.