SlideShare a Scribd company logo
What is Laravel ?
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
Google Trends (2012 – 2019)
PHP Framework Popularity at Work – 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 like Yum 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 = 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
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 ?
Ad

More Related Content

Similar to What-is-Laravel and introduciton to Laravel (20)

Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
ShaimaaMohamedGalal
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
Obinna Akunne
 
Laravel session 1
Laravel  session 1Laravel  session 1
Laravel session 1
Ashish Kumar
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
netzwelt12345
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
asif290119
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--dev
altsav
 
Laravel Meetup
Laravel MeetupLaravel Meetup
Laravel Meetup
Whisnu Sucitanuary
 
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
 
Laravel Framework Notes Web Techonologies
Laravel Framework Notes Web TechonologiesLaravel Framework Notes Web Techonologies
Laravel Framework Notes Web Techonologies
binshehzad26
 
Solr Recipes
Solr RecipesSolr Recipes
Solr Recipes
Erik Hatcher
 
Lecture #5 Introduction to rails
Lecture #5 Introduction to railsLecture #5 Introduction to rails
Lecture #5 Introduction to rails
Evgeniy Hinyuk
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy Hinyuk
Pivorak MeetUp
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
Joram Salinas
 
Web presentation
Web presentationWeb presentation
Web presentation
Solaiman Hossain Tuhin
 
Laravel Presentation
Laravel PresentationLaravel Presentation
Laravel Presentation
REZAUL KARIM REFATH
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
Shahrzad Peyman
 
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidLaravel : A Fastest Growing Kid
Laravel : A Fastest Growing Kid
Endive Software
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
Camuel Gilyadov
 
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
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
ShaimaaMohamedGalal
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
netzwelt12345
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--dev
altsav
 
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
 
Laravel Framework Notes Web Techonologies
Laravel Framework Notes Web TechonologiesLaravel Framework Notes Web Techonologies
Laravel Framework Notes Web Techonologies
binshehzad26
 
Lecture #5 Introduction to rails
Lecture #5 Introduction to railsLecture #5 Introduction to rails
Lecture #5 Introduction to rails
Evgeniy Hinyuk
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy Hinyuk
Pivorak MeetUp
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
Shahrzad Peyman
 
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidLaravel : A Fastest Growing Kid
Laravel : A Fastest Growing Kid
Endive Software
 
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
 

More from PraveenHegde20 (6)

Error Handling In PHP with all Try catch anf various runtime errors
Error Handling In PHP with all Try catch anf various runtime errorsError Handling In PHP with all Try catch anf various runtime errors
Error Handling In PHP with all Try catch anf various runtime errors
PraveenHegde20
 
PHP with Postgres SQL connection string and connecting
PHP with Postgres SQL connection string and connectingPHP with Postgres SQL connection string and connecting
PHP with Postgres SQL connection string and connecting
PraveenHegde20
 
CSS Adnaved with HTML abd complete Stylesheet
CSS Adnaved with HTML abd complete StylesheetCSS Adnaved with HTML abd complete Stylesheet
CSS Adnaved with HTML abd complete Stylesheet
PraveenHegde20
 
CSS Basics ro advanced training material
CSS Basics ro advanced training materialCSS Basics ro advanced training material
CSS Basics ro advanced training material
PraveenHegde20
 
Smart city engineering work using Internet of Things
Smart city engineering  work using Internet of ThingsSmart city engineering  work using Internet of Things
Smart city engineering work using Internet of Things
PraveenHegde20
 
Data Engineering Data warehousing Pentaho
Data Engineering  Data warehousing  PentahoData Engineering  Data warehousing  Pentaho
Data Engineering Data warehousing Pentaho
PraveenHegde20
 
Error Handling In PHP with all Try catch anf various runtime errors
Error Handling In PHP with all Try catch anf various runtime errorsError Handling In PHP with all Try catch anf various runtime errors
Error Handling In PHP with all Try catch anf various runtime errors
PraveenHegde20
 
PHP with Postgres SQL connection string and connecting
PHP with Postgres SQL connection string and connectingPHP with Postgres SQL connection string and connecting
PHP with Postgres SQL connection string and connecting
PraveenHegde20
 
CSS Adnaved with HTML abd complete Stylesheet
CSS Adnaved with HTML abd complete StylesheetCSS Adnaved with HTML abd complete Stylesheet
CSS Adnaved with HTML abd complete Stylesheet
PraveenHegde20
 
CSS Basics ro advanced training material
CSS Basics ro advanced training materialCSS Basics ro advanced training material
CSS Basics ro advanced training material
PraveenHegde20
 
Smart city engineering work using Internet of Things
Smart city engineering  work using Internet of ThingsSmart city engineering  work using Internet of Things
Smart city engineering work using Internet of Things
PraveenHegde20
 
Data Engineering Data warehousing Pentaho
Data Engineering  Data warehousing  PentahoData Engineering  Data warehousing  Pentaho
Data Engineering Data warehousing Pentaho
PraveenHegde20
 
Ad

Recently uploaded (20)

One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Ad

What-is-Laravel and introduciton to Laravel

  • 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. 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
  • 5. PHP Framework Popularity at Work – SitePoint 2015
  • 6. 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
  • 7. 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.
  • 8. 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 like Yum or apt • Per project tool (vendor folder), not per system • Install by using the command: composer create-project --prefer-dist laravel/laravel laravel-softuni
  • 9. 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
  • 10. 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)
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. Eloquent & Database • The Eloquent ORM (Object-relational mapping) provides simple ActiveRecord 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’);
  • 16. • 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
  • 17. 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
  • 18. 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.
  • 19. Views mobility Extend and include partials. For example share the same form fields on 2 pages – add and edit
  • 20. 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
  • 21. Database architecture Be careful with the database architecture, always use the proper length for specific column and never forget the indexes for searchable columns
  • 22. 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.
  • 23. 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