Laravel Basic Concepts

Followings are list of basic Concepts in Laravel:

  • Routing
  • Controllers
  • Views
  • Blade templating
  • Requests and Responses
  • Models & Migrations
  • Middleware
  • Eloquent ORM

Routing:

Routing means to accept the request and redirect it to appropriate function. Routing is a core concept in Laravel, and it works a little differently than some of the frameworks of the past. The Laravel Route system is very flexible, and although a little tricky at first. Http verbs can be used to specify an action that the route should perform when called. For example, a GET http verb is used to retrieve resources while POST http verb is used to create a resource.

For Example:

Route::get('/', function () {
   return 'Hello World';
});

Controller:

The Controller’s job is to pass information between the view and the model. The model itself is responsible for the business logic, things like accessing and returning results from a database. Follow this command to generate controller.

php artisan controller:make [Name]Controller

Views:

Views are the pages which will be displayed when accessed the app. View Component is used for the User Interface of the application. Generally, the view contains the HTML which will be served by the application. Views separates presentation logic from the application logic. A view file usually contains the information being presented to a user. View can be a complete web page or parts of page like header and footer.

Blade Templating:

Blade is a powerful easy to use template that comes with Laravel. Blade templates can be mixed with plain PHP code and it will still work. It is very easy to create a Blade template, simply create your view file and save it with the .blade.php  extension instead of .php, blade templates are typically stored in the <strong>resources/views</strong> directory. The main advantage of using blade template engine is that it allow use to create master template which can be extended by other individual pages.

Request and Responses

You may access all user input from request object. There is request helper in laravel. You can use Request Object anywhere. For example request()->field_name

In Laravel, a response is what sent back to the user’s browser when a request made. All routes and controllers are meant to return some response as per the request. In Laravel, a response can be return in various ways.

Models and Migrations:

Model are means to handle the business logic in any MVC framework based application. In Laravel, Model is a class that represents the logical structure and relationship of underlying data table. In Laravel, each of the database table has a corresponding “Model” that allow us to interact with that table. Models gives you the way to retrieve, insert, and update information into your data table.

Migrations gives you a way to keep track of the changes we made in database schema during the development process. In collaborative development environment migrations helps you to keep database schema in sync without having to drop and re-create the database each time a change happens.

Middleware:

Middleware is a filtering mechanism that facilitates filtering of incoming HTTP request before it is routed to particular controller for further processing. Laravel framework includes several in-built middleware, including authentication and CSRF protection.

Eloquent ORM:

Eloquent ORM refer to an advanced implementation of the PHP Active Record Pattern, which makes it very easy to interact with application database. Eloquent ORM is the very powerful yet very expressive ORM, which allow us to work with the database objects and relationships using much eloquent and expressive syntax. In Laravel, each database table is mapped into corresponding eloquent model and each of the eloquent model object include various methods for retrieving and updating the database.

 

 

 

Leave a comment