SlideShare a Scribd company logo
1 of 25
What is Laravel ?
By Georgi Genov
About me
• Georgi Genov - 25 years old
• Programming since 7 years
• I wrote my first code when I was 15 years old
• Graduated Mathematical School in Pazardzhik and then
Technical University of Sofia, Automation engineer
• Currently working as Team Leader in software company and
Freelancer, so I can be up to date with the latest technologies
ggenov
www.ggenov.eu
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
What is ?
• 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
• Lets see some statistics
GoogleTrends (2012 – 2017)
PHP Framework Popularity atWork – SitePoint 2015
Features
• Eloquent ORM (object-relational mapping) – implements ActiveRecord
• 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
Must have packages
• Laravel debugbar - https://github.com/barryvdh/laravel-debugbar
Great for debugging on local environment. Shows all the views, requests, exceptions
loaded for the current page.
• LaravelCollective – Forms & HTML - https://laravelcollective.com/docs/master/html
Perfect for generating forms, inputs, script tags and style tags
• Laravel IDE Helper - https://github.com/barryvdh/laravel-ide-helper
The package helps your IDE with autocomplete and autosuggest methods, views,
functions and more.
Let’s install Laravel
• Laravel uses Composer to manage its dependencies
• Composer is dependency management tool for PHP, like a
library full of books
• NOT likeYum or apt
• Per project tool (vendor folder), not per system
• Install by using the command:
composer create-project --prefer-dist laravel/laravel
laravel-softuni
The structure
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
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 !
• 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
Routing
• 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
Middleware
• The middleware is mechanism for
filtering the HTTP requests
• Laravel includes several middlewares –
Authentication,CSRF Protection
• The auth middleware checks if the user
visting 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
Blade
• 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
Eloquent & Database
• The Eloquent ORM (Object-relational mapping) provides simple ActiveRecord implementation
for working with the database
$article = newArticle();
$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
We will play with Laravel and create CRUD for recipes (Create, Read, Update, Delete).
The recipe will have the following columns / fields :
• Id – primary key – not null
• Title – varchar – 255 length – not null
• Description – text – nullable
• Status – enum [ active / inactive ] – not null – defaults to active
• Created At – datetime – not null
• Updated At – datetime – not null
Best practices in Laravel
NEVER write queries or model logic inside the controller!The controller
job is to communicate with the model and pass data to the view.
Views mobility
Extend and include partials. For example share the
same form fields on 2 pages – add and edit
Forms security
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
Database architecture
Be careful with the database architecture, always use the proper length for specific column and
never forget the indexes for searchable columns
Big query
• 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.
Don’t forget the PHPDoc
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
Thank you! Questions ?

More Related Content

What's hot

Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5Soheil Khodayari
 
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 ArtisansWindzoon Technologies
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
Laravel tutorial
Laravel tutorialLaravel tutorial
Laravel tutorialBroker IG
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafThymeleaf
 
Ingénieur FullStack Java/Angular
Ingénieur FullStack Java/Angular  Ingénieur FullStack Java/Angular
Ingénieur FullStack Java/Angular Maroua Haddad
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash CourseHaim Michael
 
Oracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ OverviewOracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ OverviewKris Rice
 

What's hot (20)

laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
Laravel
LaravelLaravel
Laravel
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Laravel
LaravelLaravel
Laravel
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
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
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
Laravel tutorial
Laravel tutorialLaravel tutorial
Laravel tutorial
 
Laravel Presentation
Laravel PresentationLaravel Presentation
Laravel Presentation
 
Laravel Eloquent ORM
Laravel Eloquent ORMLaravel Eloquent ORM
Laravel Eloquent ORM
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
 
Ingénieur FullStack Java/Angular
Ingénieur FullStack Java/Angular  Ingénieur FullStack Java/Angular
Ingénieur FullStack Java/Angular
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash Course
 
Laravel 101
Laravel 101Laravel 101
Laravel 101
 
Oracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ OverviewOracle REST Data Services Best Practices/ Overview
Oracle REST Data Services Best Practices/ Overview
 

Similar to What-is-Laravel-23-August-2017.pptx

Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfShaimaaMohamedGalal
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravelDerek Binkley
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--devaltsav
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!netzwelt12345
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsTaylor Lovett
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterpriseTaylor Lovett
 
Headless cms architecture
Headless cms architectureHeadless cms architecture
Headless cms architectureKevin Wenger
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
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...44CON
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
 
Introduction_Web_Technologies
Introduction_Web_TechnologiesIntroduction_Web_Technologies
Introduction_Web_TechnologiesDeepak Raj
 
Middleware in Golang: InVision's Rye
Middleware in Golang: InVision's RyeMiddleware in Golang: InVision's Rye
Middleware in Golang: InVision's RyeCale Hoopes
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsAchievers Tech
 

Similar to What-is-Laravel-23-August-2017.pptx (20)

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
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Laravel session 1
Laravel  session 1Laravel  session 1
Laravel session 1
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--dev
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Laravel Meetup
Laravel MeetupLaravel Meetup
Laravel Meetup
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
The ABC's of IaC
The ABC's of IaCThe ABC's of IaC
The ABC's of IaC
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
 
Headless cms architecture
Headless cms architectureHeadless cms architecture
Headless cms architecture
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
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...
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
Introduction_Web_Technologies
Introduction_Web_TechnologiesIntroduction_Web_Technologies
Introduction_Web_Technologies
 
Middleware in Golang: InVision's Rye
Middleware in Golang: InVision's RyeMiddleware in Golang: InVision's Rye
Middleware in Golang: InVision's Rye
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty Details
 

Recently uploaded

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 Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 interpreternaman860154
 
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 textsMaria Levchenko
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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...Enterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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 2024Rafal Los
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Recently uploaded (20)

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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

What-is-Laravel-23-August-2017.pptx

  • 1. What is Laravel ? By Georgi Genov
  • 2. About me • Georgi Genov - 25 years old • Programming since 7 years • I wrote my first code when I was 15 years old • Graduated Mathematical School in Pazardzhik and then Technical University of Sofia, Automation engineer • Currently working as Team Leader in software company and Freelancer, so I can be up to date with the latest technologies ggenov www.ggenov.eu
  • 3. 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
  • 4. What is ? • 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 • Lets see some statistics
  • 6. PHP Framework Popularity atWork – SitePoint 2015
  • 7. Features • Eloquent ORM (object-relational mapping) – implements ActiveRecord • 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
  • 8. Must have packages • Laravel debugbar - https://github.com/barryvdh/laravel-debugbar Great for debugging on local environment. Shows all the views, requests, exceptions loaded for the current page. • LaravelCollective – Forms & HTML - https://laravelcollective.com/docs/master/html Perfect for generating forms, inputs, script tags and style tags • Laravel IDE Helper - https://github.com/barryvdh/laravel-ide-helper The package helps your IDE with autocomplete and autosuggest methods, views, functions and more.
  • 9. Let’s install Laravel • Laravel uses Composer to manage its dependencies • Composer is dependency management tool for PHP, like a library full of books • NOT likeYum or apt • Per project tool (vendor folder), not per system • Install by using the command: composer create-project --prefer-dist laravel/laravel laravel-softuni
  • 10. The structure 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
  • 11. 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)
  • 12. Artisan ! • 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
  • 13. Routing • 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
  • 14. Middleware • The middleware is mechanism for filtering the HTTP requests • Laravel includes several middlewares – Authentication,CSRF Protection • The auth middleware checks if the user visting 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
  • 15. Blade • 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
  • 16. Eloquent & Database • The Eloquent ORM (Object-relational mapping) provides simple ActiveRecord implementation for working with the database $article = newArticle(); $article->title = ‘Article title’; $article->description = ‘Description’; $article->save(); INSERT INTO `article` (`title`, `description`)VALUES (‘Article title’, ‘Description’);
  • 17. • 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
  • 18. Practical task We will play with Laravel and create CRUD for recipes (Create, Read, Update, Delete). The recipe will have the following columns / fields : • Id – primary key – not null • Title – varchar – 255 length – not null • Description – text – nullable • Status – enum [ active / inactive ] – not null – defaults to active • Created At – datetime – not null • Updated At – datetime – not null
  • 19. Best practices in Laravel NEVER write queries or model logic inside the controller!The controller job is to communicate with the model and pass data to the view.
  • 20. Views mobility Extend and include partials. For example share the same form fields on 2 pages – add and edit
  • 21. Forms security 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
  • 22. Database architecture Be careful with the database architecture, always use the proper length for specific column and never forget the indexes for searchable columns
  • 23. Big query • 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.
  • 24. Don’t forget the PHPDoc 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