Laravel framework systems Routing and Controllers


Laravel framework systems Routing and Controllers

In this article, we provide you with a set of details about Laravel framework systems, it is known that Laravel is one of the most important frameworks for php.

Using Laravel can provide an integrated work environment, in which you will find everything you need while working in this framework.

The directions systems in Laravel are simple and easy, it takes about 20 seconds to create a new page, it may take only 3 minutes to create an integrated page.

This is a general form of the directive in Laravel as follows:





Simplified routing process in Laravel framework

The simplified routing process in Laravel framework systems relies on redirecting to a specific function, after which certain content is retrieved, soon this message appears: "Hello World From Laravel".

Route::get('page-link' , function(){    return "Hello World From Laravel";});

There are other types used in the routing process, in this article, we will review the most popular systems that are integrated from the latest version of Laravel 8.

In case of directing to a Controller, it is considered a php class and derives most of its properties from the main Controller class that can be obtained when installing Laravel.

Route::get('page-link' , '[email protected]');

Larvel Systems , Controllers

A controller is one of the most important systems of the Laravel framework and control systems in Arabic language, it's the main core of the project.

In these files, we can create various operations for any project, then send them back to the pages that will appear to the user.

To create a controller in Laravel, this can be done using this command in the "Command Line" menu.

php artisan make:controller ControllerName 

If you are trying to find the controller location when installing a project, it can be found using the following path: app/Http/Controllers

In case of creating a Controller, it is possible to give any name to the Controller, but it is better to use a writing method that includes the name of the Controller at the beginning of the name and then the word "Controller".

For example, "AdminController" is better than writing it in this way "controllerForAdminStuff".

In both cases, the naming is correct, but following accepted rules is better and easier, after a controller is completed, this calculation can be done.

<?php namespace App\Http\Controllers; class Admin extends Controller{    public function count(){        $a = 1; $b = 2; $c = $a + $b; return $c;     }}

In this way, the work of the controller has been successfully completed, of course, the controller is used to do much larger tasks, but it is sufficient in the previous example to test its success only.

In case of viewing this result, a new Route should be created and directed to Controller to view the result, through this code in the file, .routes/web.php.

Route::get('count' , '[email protected]'); //Change ControllerName to Your Controller Name to Avoid Errors...

The result is shown on the page, which is of course, the sum of the number: 3, this is a general idea of ​​creating a controller.

A lot of arithmetic operations can be done after advancing the level and getting more experience of what can be done through Laravel.

In the next article, we will talk about Views, which is one of the most important systems in Laravel framework, it is the element we need to show everything that is being done on the page, it is the second element in MVC structure.