SlideShare ist ein Scribd-Unternehmen logo
1 von 22
By:
Mayank Panchal
We will learn today
• WHAT IS LARAVEL
• INSTALL LARAVEL 5 WITH COMPOSER
• FILES STRUCTURE
• WHAT IS ARTISAN AND HOW DOES IT SAVE US TIME
• ROUTING AND ROUTE TYPES
• WHAT IS MIDDLEWARE AND HOW TO USE IT
• WHAT IS BLADE ?
• DATABASE AND ELOQUENT ORM
• CRUD WITH VALIDATION AND DATABASE
CONNECTION (PRACTICAL TASK)
• BEST PRACTICES WHEN CODING IN LARAVEL
• Laravel is MVC PHP framework created by Taylor Otwell in
2011
• Free open-source license with many contributors worldwide
• One of the best frameworks together with Symfony,
CodeIgniter, Yii
• Has powerful features, saving us time
• Uses Symfony packages
What is
• Eloquent ORM (object-relational mapping) – implements Active-
Record
• Query builder – helps you to build secured SQL queries
• Restful controllers – provides a way for separating the different HTTP
requests (GET, POST, DELETE, etc.)
• Blade template engine – combines templates with a data model to
produce views
• Migrations – version control system for database, update your database
easier
• Database seeding – provides a way to populate database tables with test
data used for testing
• Pagination – easy to use advanced pagination functionalities
• Forms security – provides CSRF token middleware, protecting all the
forms
Features of
• Laravel uses Composer to manage its dependencies
• Composer is dependency management tool for PHP, like a library full of
books
• NOT like Yum or apt
• Per project tool (vendor folder), not per system
• Install by using the command:
composer create-project [PACKAGE] [DESTINATION PATH] [--FLAGS]
composer create-project laravel/laravel Laravel test
Let’s install
app/Http folder contains the Controllers, Middlewares and Kernel file
All the models should be located in app/Models folder
All the config files are located in app/config folder
The service providers that are bootstrapping functions in our
app are located in app/Providers folder
Folder Structure
Folder Structure
• Database folder contains the migrations and
seeds
• The public folder is the actual folder you are opening on
the web server.
All JS / CSS / Images / Uploads are located there.
• The resources folder contains all the translations, views
and assets (SASS, LESS, JS)
that are compiled into public folder
• The routes folder contains all the routes for the project
• All the logs / cache files are located in storage folder
• The vendor folder contains all the composer packages
(dependencies)
Artisan is command-line interface for Laravel
Commands that are saving time
Generating files with artisan is recommended
Run php artisan list in the console
Artisan!
• The best and easy routing system I’ve seen
• Routing per middleware / prefix or namespace
• Routing per request method (GET, POST,
DELETE, etc.)
• ALWAYS name your route !
• Be careful with the routing order !
Let’s see routing examples
Routing
• The middleware is mechanism for filtering the HTTP
requests
• Laravel includes several middleware's – Authentication,
CSRF Protection
• The auth middleware checks if the user visiting the page
is authenticated through session cookie
• The CSRF token protection middleware protects your
application from cross-site request forgery attacks by
adding token key for each generated form
Let’s create middleware
Middleware
• Blade is the powerful template engine provided by
Laravel
• All the code inside blade file is compiled to static html
file
• Supports plain PHP
• Saves time
• Better components mobility, extend and include partials
Let’s take a look at few examples
Blade
ELOQUENT & DATABASE
• THE ELOQUENT ORM (OBJECT-RELATIONAL MAPPING) PROVIDES SIMPLE ACTIVE RECORD
IMPLEMENTATION FOR WORKING WITH THE DATABASE
$article = new Article();
$article->title = ‘Article title’;
$article->description = ‘Description’;
$article->save();
INSERT INTO `article` (`title`, `description`) VALUES (‘Article title’, ‘Description’);
• EACH TABLE HAS ITS OWN “MODEL”. YOU CAN USE THE MODEL TO READ, INSERT, UPDATE OR
DELETE ROW FROM THE SPECIFIC TABLE
• LET’S CHECK ONE MODEL
Practical Task
Best practices in
• NEVER write queries or model logic inside
the controller! The controller job is to
communicate with the model and pass data to
the view.
Extend and include partials. For example share
the same form fields on 2 pages – add and edit
Views mobility
Always use the CSRF token protection that Laravel provides in forms you create, the hackers will not
be able to spam your forms and database
Forms security
Be careful with the database architecture, always use the proper length for specific column and never
forget the indexes for searchable columns
Database architecture
• Avoid the big query unless you really have
to do it. The big query is hard to debug
and understand.
• You can merge the small queries into one
to save the CPU time on server, but
sometimes the query becomes way too
big.
Big Query
Don’t forget to write comments for each
method or complicated logic.
The PHPDoc comments are helping the
IDE to autosuggest easier and the
developers to understand the piece of code
Don’t forget the PHPDoc
Thank you!
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xampp
Jin Castor
 

Was ist angesagt? (20)

PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Laravel
LaravelLaravel
Laravel
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web Artisans
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
MERN PPT
MERN PPTMERN PPT
MERN PPT
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Soap vs rest
Soap vs restSoap vs rest
Soap vs rest
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xampp
 
Laravel tutorial
Laravel tutorialLaravel tutorial
Laravel tutorial
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Web api
Web apiWeb api
Web api
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 

Ähnlich wie Laravel ppt

Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
Erik Hatcher
 

Ähnlich wie Laravel ppt (20)

What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptx
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
Solr Recipes
Solr RecipesSolr Recipes
Solr Recipes
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
Laravel 4 presentation
Laravel 4 presentationLaravel 4 presentation
Laravel 4 presentation
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
Lecture #5 Introduction to rails
Lecture #5 Introduction to railsLecture #5 Introduction to rails
Lecture #5 Introduction to rails
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy Hinyuk
 
Directory Structure Changes in Laravel 5.3
Directory Structure Changes in Laravel 5.3Directory Structure Changes in Laravel 5.3
Directory Structure Changes in Laravel 5.3
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
 
SilverStripe From a Developer's Perspective
SilverStripe From a Developer's PerspectiveSilverStripe From a Developer's Perspective
SilverStripe From a Developer's Perspective
 
MySQL Day Paris 2016 - MySQL as a Document Store
MySQL Day Paris 2016 - MySQL as a Document StoreMySQL Day Paris 2016 - MySQL as a Document Store
MySQL Day Paris 2016 - MySQL as a Document Store
 
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
Salesforce Basic Development
Salesforce Basic DevelopmentSalesforce Basic Development
Salesforce Basic Development
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Laravel ppt

  • 2. We will learn today • WHAT IS LARAVEL • INSTALL LARAVEL 5 WITH COMPOSER • FILES STRUCTURE • WHAT IS ARTISAN AND HOW DOES IT SAVE US TIME • ROUTING AND ROUTE TYPES • WHAT IS MIDDLEWARE AND HOW TO USE IT • WHAT IS BLADE ? • DATABASE AND ELOQUENT ORM • CRUD WITH VALIDATION AND DATABASE CONNECTION (PRACTICAL TASK) • BEST PRACTICES WHEN CODING IN LARAVEL
  • 3. • Laravel is MVC PHP framework created by Taylor Otwell in 2011 • Free open-source license with many contributors worldwide • One of the best frameworks together with Symfony, CodeIgniter, Yii • Has powerful features, saving us time • Uses Symfony packages What is
  • 4.
  • 5. • Eloquent ORM (object-relational mapping) – implements Active- Record • Query builder – helps you to build secured SQL queries • Restful controllers – provides a way for separating the different HTTP requests (GET, POST, DELETE, etc.) • Blade template engine – combines templates with a data model to produce views • Migrations – version control system for database, update your database easier • Database seeding – provides a way to populate database tables with test data used for testing • Pagination – easy to use advanced pagination functionalities • Forms security – provides CSRF token middleware, protecting all the forms Features of
  • 6. • Laravel uses Composer to manage its dependencies • Composer is dependency management tool for PHP, like a library full of books • NOT like Yum or apt • Per project tool (vendor folder), not per system • Install by using the command: composer create-project [PACKAGE] [DESTINATION PATH] [--FLAGS] composer create-project laravel/laravel Laravel test Let’s install
  • 7. app/Http folder contains the Controllers, Middlewares and Kernel file All the models should be located in app/Models folder All the config files are located in app/config folder The service providers that are bootstrapping functions in our app are located in app/Providers folder Folder Structure
  • 8. Folder Structure • Database folder contains the migrations and seeds • The public folder is the actual folder you are opening on the web server. All JS / CSS / Images / Uploads are located there. • The resources folder contains all the translations, views and assets (SASS, LESS, JS) that are compiled into public folder • The routes folder contains all the routes for the project • All the logs / cache files are located in storage folder • The vendor folder contains all the composer packages (dependencies)
  • 9. Artisan is command-line interface for Laravel Commands that are saving time Generating files with artisan is recommended Run php artisan list in the console Artisan!
  • 10. • The best and easy routing system I’ve seen • Routing per middleware / prefix or namespace • Routing per request method (GET, POST, DELETE, etc.) • ALWAYS name your route ! • Be careful with the routing order ! Let’s see routing examples Routing
  • 11. • The middleware is mechanism for filtering the HTTP requests • Laravel includes several middleware's – Authentication, CSRF Protection • The auth middleware checks if the user visiting the page is authenticated through session cookie • The CSRF token protection middleware protects your application from cross-site request forgery attacks by adding token key for each generated form Let’s create middleware Middleware
  • 12. • Blade is the powerful template engine provided by Laravel • All the code inside blade file is compiled to static html file • Supports plain PHP • Saves time • Better components mobility, extend and include partials Let’s take a look at few examples Blade
  • 13. ELOQUENT & DATABASE • THE ELOQUENT ORM (OBJECT-RELATIONAL MAPPING) PROVIDES SIMPLE ACTIVE RECORD IMPLEMENTATION FOR WORKING WITH THE DATABASE $article = new Article(); $article->title = ‘Article title’; $article->description = ‘Description’; $article->save(); INSERT INTO `article` (`title`, `description`) VALUES (‘Article title’, ‘Description’);
  • 14. • EACH TABLE HAS ITS OWN “MODEL”. YOU CAN USE THE MODEL TO READ, INSERT, UPDATE OR DELETE ROW FROM THE SPECIFIC TABLE • LET’S CHECK ONE MODEL
  • 16. Best practices in • NEVER write queries or model logic inside the controller! The controller job is to communicate with the model and pass data to the view.
  • 17. Extend and include partials. For example share the same form fields on 2 pages – add and edit Views mobility
  • 18. Always use the CSRF token protection that Laravel provides in forms you create, the hackers will not be able to spam your forms and database Forms security
  • 19. Be careful with the database architecture, always use the proper length for specific column and never forget the indexes for searchable columns Database architecture
  • 20. • Avoid the big query unless you really have to do it. The big query is hard to debug and understand. • You can merge the small queries into one to save the CPU time on server, but sometimes the query becomes way too big. Big Query
  • 21. Don’t forget to write comments for each method or complicated logic. The PHPDoc comments are helping the IDE to autosuggest easier and the developers to understand the piece of code Don’t forget the PHPDoc