Professional Documents
Culture Documents
LARAVEL Notes
LARAVEL Notes
PREPARED BY
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
Authentication
Effective ORM
Laravel framework can expand the database and the migration process of
Laravel is very secure and full-proof. In the whole process, php
code is used rather than SQL code.
Unique Unit-testing
Intact Security
What Is Laravel
History:
The Laravel Framework was developed by Taylor Otwell and released to
the public in the year 2011.
The following table shows the different versions of Laravel.
Version Date of Release PHP Version Support
So what do you think, which one is the most popular PHP Framework? The
answer is Laravel.
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
The following screenshot of Google Trends shows the analysis of the
popularity of different PHP frameworks.
Advantages:
The following list shows some advantages of the Laravel Framework.
• Follows MVC architectural design pattern
• Free and open-source
• Easy to learn
• Good documentation support
• Easy to integrate
• High performance and efficiency
• A high level of security
Features:
Laravel has a rich set of features. These are as follows:
• Modularity: Laravel has many built-in libraries and modules which
help developers to build responsive and modular PHP web
applications. This feature also speeds up development.
• Lazy Collection: It handles heavy loads of data with the minimum
usage of memory.
• Eloquent ORM: ORM stands for Object Relation Mapping. Laravel has
a built-in ORM called Eloquent which handles database related
operations.
• Artisan: Artisan is the command-line interface used in Laravel.
• Blade templates: Laravel has a concept called Blade, which
creates a unique template to display data.
• Unit testing: Test cases can be used to perform unit testing in
Laravel.
• Email support: Laravel has a built-in class called Mail, which
helps to send emails.
• Authentication: Authentication is used to identify the users of
the system. It is usually achieved by identifying the username
and password of the user.
MVC Architecture Of Laravel
The Laravel Framework follows MVC architecture. MVC is an
architectural design pattern that helps to develop web applications
faster. MVC stands for Model-View-Controller.
• Model (M)–A model handles data used by the web application.
• View (V)–A view helps to display data to the user.
• Controller (C)–A controller interacts with the model to create
data for the view.
The following screenshot shows the interactions between Model, View,
and Controller.
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
composer
cd laravel-tutorial
Then, run the following command in the command prompt to start the
Laravel development server.
return view('welcome');
});
The following command can be run in the command prompt to get the full
list of registered routes.
Creating a Route
Step 1: Add the following code segment in routes/web.php file to
register a new route.
Route::get('/example', function () {
});
Routing Parameters
The Laravel Framework uses two types of route parameters.
return $name;
});
return $name;
});
Named Routes
In the following route, the report controller will call the
function showReport with parameters as the report.
Route::get(student/report, 'ReportController@showReport')-
>name(report);
Introduction To Views
In MVC architecture, the character ‘V’ stands for View. Views contain
HTML, CSS and JavaScript. The Views represent the frontend of the
Laravel application, and it is used to display the content for the
user.
All the views are stored in the resources/views directory. By default,
the Laravel Framework provides the welcome.blade.php file.
Creating a View
Step 1: Create a view named index.php in the resources/views directory
and save the following code.
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello World!</h1>
</body>
</html>
return view('index');
});
<html lang="en">
<body>
</body>
</html>
});
<html lang="en">
<body>
</body>
</html>
<html lang="en">
<body>
</body>
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
</html>
Laravel Controllers
In MVC architecture, the character ‘C’ stands for Controller. A
controller communicates with the relevant model if necessary and loads
the view to display the content for the user.
All the controllers are stored in the app/Http/Controllers directory.
Creating a Controller
Run the following command in the command prompt to create a controller
named UserContoller.
php artisan make:controller UserController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
return view('assessment');
<html lang="en">
<body>
<h1>Laravel Assessment</h1>
</body>
</html>
The following table shows the actions handled by the Restful Resource
Controllers:
Request
Path (URI) Action Route Name Use
Type
What Is Middleware
In simple words, middleware is a bridge between a request and a
response. It provides a mechanism to filter HTTP requests.
All the middleware files are stored in
the app/Http/Middleware directory.
The Laravel Framework has a middleware to check whether the user of
the Laravel application is authenticated or not. If the user is
authenticated, it directs to the home page and if the user is not
authenticated, it redirects to the login page.
Creating a Middleware
Step 1: Run the following command in the command prompt to create a
middleware called CheckUser.
php artisan make:middleware CheckUser
namespace App\Http\Middleware;
use Closure;
class CheckUser
{
WEB PROGRAMMING PROF.SMITHA JACOB SJCET,PALAI
/**
return $next($request);
Step 3: Open the Kernel.php file in the app/Http directory and add the
path of the CheckUser middleware as shown below.
protected $routeMiddleware = [
];
namespace App\Http\Controllers;
use Illuminate\Http\Request;
return view('assessment');
Conclusion
The Laravel Framework is a popular, free, and open-source MVC based
web framework for PHP. It is used to develop complex PHP web
applications. In Laravel, registered routes direct the request to the
relevant function of the controller. Then the controller communicates
with the relevant model, if necessary, and loads the view to display
the content for the user.
Middleware acts as a bridge between a request and a response. Laravel
uses a special concept called Blade to design a unique layout to
display data, and it can be used by other views.