LECTURE 0
INT 221(MVC PROGRAMMING)
Course Details
LTP – 2 0 2
Syllabus
- Introduction to MVC Laravel Framework
- Request, Routing & Responses
- Controllers, Blade and Advanced Routing
- URL Generation, Request Data and Emails
- Laravel Localization and Sessions
- Laravel Forms and Validation
- Databases, Schema Builder and Migrations
Course Outcomes
- Understand the directory structure and request response life cycle in Laravel
- Develop flexible, user-friendly and clean web applications
- Demonstrate well-organized, reusable and maintainable code using views and controllers
- Use forms and gather and validate inputs
- Make cookies and sessions to store users information across the requests
- Construct a database and use appropriate SQL statements to create tables and store data
Introduction
- Laravel is an open-source widely used PHP framework.
- The platform was intended for the development of web application by using MVC architectural pattern.
- Laravel is released under the MIT license. Therefore, its source code is hosted on GitHub.
Introduction
- It is a reliable PHP framework as it follows expressive and accurate language rules.
- It comes with a robust collection of tools and provides application architecture.
- Taylor Otwell developed Laravel in July 2011
Laravel Versions
- Laravel 1
- Laravel 2
- Laravel 3
- Laravel 4
- Laravel 5
- Laravel 6
- Laravel 7
- Laravel 8
Features of Laravel
- Routing controllers – flexible approach to the user to define routes
- Configuration management – provides a consistent approach to handle the configuration
- Testability – features and helpers which helps in testing through various test cases
- Authentication and authorization of users – features such as register, forgot password and send password reminders.
- Modularity – built in libraries and modules which helps in enhancement of the application
Features of Laravel(contd.)
- Query builder – incorporates a query builder which helps in querying databases using various simple chain methods
- Provides a template engine – uses the Blade Template engine, a lightweight template language
- Building schemas – maintains the database definitions and schema in PHP code
- E-mailing facilities – includes a mail class which helps in sending mail with rich content and attachments from the web application
Why Laravel?
- A Scalable Framework
- Considerable time is saved in designing the web application due to reusability
- Laravel may serve as a full stack framework. By “full stack” framework it means that you are going to use Laravel to route requests to your application and render your frontend via Blade templates.
- Laravel has a very rich set of features which will boost the speed of web development.
Composer
- Composer is a dependency manager for a PHP programming language that manages the dependencies of PHP software and required libraries.
- Composer runs through the command line. The main purpose of the composer is to install the dependencies or libraries for an application.
Artisan
- Command line interface used in Laravel is called Artisan.
- It includes a set of commands which assists in building a web application.
Installation Via Composer
- Laravel implements a composer for managing dependencies within it.
- Hence, before the use of Laravel, it needs to check whether you have a composer setup on your system or not.
- If you don’t have Composer installed on your computer, first visit this URL to download Composer:
https://getcomposer.org/download/
Installation Via Composer(contd.)
- When you are done installing the Composer, cross-check whether it is installed or not by typing in the command prompt the composer command.
- C:\Users\dell>composer
Creating project
- The next thing you have to do is make a new folder in some specific path within your system for keeping your Laravel projects. Move to that location where the directory is created. For installing the Laravel, the following command you have to type: composer create-project laravel/laravel Laravel2022
- The command mentioned above will make Laravel installed on that specific directory.
Creating project(contd.)
php artisan serve
- This above code will start the Laravel service
Laravel Application Structure
Laravel Application Structure(contd.)
The App Directory:
- The app directory contains the core code of your application.
The Bootstrap Directory:
- The bootstrap directory contains the app.php file which bootstraps the framework.
- This directory also houses a cache directory which contains framework generated files for performance optimization such as the route and services cache files.
Laravel Application Structure(contd.)
The Config Directory:
- The config directory contains all of your application’s configuration files.
The Database Directory:
- The database directory contains your database migrations, model factories, and seeds.
Laravel Application Structure(contd.)
The Public Directory:
- The public directory contains the index.php file, which is the entry point for all requests entering your application and configures autoloading.
- This directory also houses your assets such as images, JavaScript, and CSS.
Laravel Application Structure(contd.)
The Resources Directory:
- The resources directory contains your views as well as your raw, un-compiled assets such as CSS or JavaScript.
- This directory also houses all of your language files.
The Routes Directory:
- The routes directory contains all of the route definitions for your application.
- By default, several route files are included with Laravel: web.php, api.php, console.php, and channels.php.
Laravel Application Structure(contd.)
The Storage Directory:
- The storage directory contains your logs, compiled Blade templates, file based sessions, file caches, and other files generated by the framework.
- This directory is segregated into app, framework, and logs directories.
Laravel Application Structure(contd.)
- The Tests Directory – The tests directory contains your automated tests
- The Vendor Directory – The vendor directory contains your Composer dependencies.
Laravel Application Structure(contd.)
- For more information, go to https://laravel.com/docs/8.x/structure#the-routes- directory
The App directory
The console directory:
- The Console directory contains all of the custom Artisan commands for your application.
- These commands may be generated using the make:command command.
- This directory also houses your console kernel, which is where your custom Artisan commands are registered and your scheduled tasks are defined.
The App directory(contd.)
The Exceptions Directory:
- The Exceptions directory contains your application’s exception handler and is also a good place to place any exceptions thrown by your application.
- If you would like to customize how your exceptions are logged or rendered, you should modify the Handler class in this directory.
The App directory(contd.)
The Http Directory:
- The Http directory contains your controllers, middleware, and form requests.
- Almost all of the logic to handle requests entering your application will be placed in this directory.
The App directory(contd.)
The Providers Directory:
- The Providers directory contains all of the service providers for your application.
- Service providers bootstrap your application by binding services in the service container, registering events, or performing any other tasks to prepare your application for incoming requests.
The App directory(contd.)
Following are the list of directories that don’t exist in the app directory by default but can be created:
- The Broadcasting Directory
- The Events Directory
- The Jobs Directory
- The Listeners Directory
- The Mail Directory
- The Notifications Directory
- The Policies Directory
The routes directory
- The Laravel application’s routes directory contains all of the route definitions for your application. By default, several route files are included in a Laravel project like web.php, api.php, console.php, and channels.php, etc.
web.php:
- The web.php file consists of the routes that are the RouteServiceProvider places in the web middleware group
- All of your Laravel app routes will most likely be defined in the web.php file.
The routes directory(contd.)
api.php:
- The api.php file contains routes that the RouteServiceProvider places in the API middleware group.