SlideShare a Scribd company logo
Object-Oriented
Programming
(with Laravel)
By: Shahrzad Peyman
Session 2
April-2017
shahrzad.peyman@gmail.com
1
2
Today’s Presentation
• Encapsulation, Access Level and Inheritance
• Local Development Server
• Front Controller
• Configuration
• Directory Structure
• The Root Directory
• The App Directory
• Routing
• Controllers
Encapsulation
• In basic terms, it’s the way we define the
visibility of our properties and methods.
• When you’re creating classes, you have to
ask yourself what properties and methods
can be accessed outside of the class.
3
Access Levels
Specifier Class SubClass all
Private *
Protected * *
Public * * *
4
Inheritance
• In object-oriented programming, inheritance
is when a class is based on another class,
using the same implementation or specifying
a new implementation to maintain the same
behavior.
• Such an inherited class is called a subclass
of its parent class or super class.
5
Inheritance
6
Inheritance
7
Local Development Server
• If you have PHP installed locally and you
would like to use PHP's built-in development
server to serve your application, you may use
the serve artisan command.
• This command will start a development
server at http://localhost:8000
• Of course, more robust local development
options are available via Homestead and Valet.
8
Front Controller
• Like HTTP itself, the Request and Response objects are
pretty simple. The hard part of building an application
is writing what comes in between. In other words, the
real work comes in writing the code that interprets the
request information and creates the response
• Your application probably does many things, like
sending emails, handling form submissions, saving
things to a database, rendering HTML pages and
protecting content with security. How can you manage
all of this and still keep your code organized and
maintainable?
Front Controller
• Traditionally, applications were built so that each
"page" of a site was its own physical file:
A. index.php
B. contact.php
C. blog.php
• There are several problems with this approach,
including the inflexibility of the URLs (what if you
wanted to change blog.php to news.php without
breaking all of your links?) and the fact that each
file must manually include some set of core files
so that security, database connections and the
"look" of the site can remain consistent.
Front Controller
• A much better solution is to use a front
controller: a single PHP file that handles
every request coming into your application.
• Now, every request is handled exactly the
same way. Instead of individual URLs
executing different PHP files, the front
controller is always executed, and the routing
of different URLs to different parts of your
application is done internally.
Configuration
Public Directory:
After installing Laravel, you should configure
your web server's document / web root to be
the public directory.
The index.php in this directory serves as the
front controller for all HTTP requests entering
your application.
12
Configuration
Config Directory:
All of the configuration files for the Laravel
framework are stored in the config directory.
Application Key:
The next thing you should do after installing Laravel
is set your application key to a random string. If you
installed Laravel via Composer or the Laravel
installer, this key has already been set for you by the
php artisan key:generate command.
13
Configuration
Configuration Caching:
To give your application a speed boost, you should
cache all of your configuration files into a single file
using the config:cache Artisan command.
This will combine all of the configuration options for
your application into a single file which will be loaded
quickly by the framework.
14
Configuration
Maintenance Mode:
When your application is in maintenance mode, a
custom view will be displayed for all requests into
your application. This makes it easy to "disable"
your application while it is updating or when you are
performing maintenance.
To enable maintenance mode, simply execute the
down Artisan command: php artisan down.
To disable maintenance mode, use the up command.
15
Directory Structure
The default Laravel application structure is
intended to provide a great starting point for
both large and small applications. Of course, you
are free to organize your application however
you like.
Where is Models Directory?
16
The Root Directory
• App
• Bootstrap
• Config
• Database
• Public
• Resources
• Routes
• Storage
• Tests
• Vendor
17
18
The App Directory
The majority of your application is housed in the App
directory. By default, this directory is namespaced under
App and is autoloaded by Composer using the PSR-4
autoloading standard.
The App directory contains a variety of additional
directories such as Console, Http and Providers. Think of
the Console and Http directories as providing an API into
the core of your application. The HTTP protocol and CLI
are both mechanisms to interact with your application,
but do not actually contain application logic.
Routing
The most basic Laravel routes simply accept a
URI and a Closure, providing a very simple and
expressive method of defining routes:
All Laravel routes are defined in your route
files, which are located in the routes directory.
19
Available Router Methods
20
Route Parameters
21
Regular Expression Constraints
22
Global Constraints
If you would like a route parameter to always be
constrained by a given regular expression, you
may use the pattern method. You should define
these patterns in the boot method of your
RouteServiceProvider:
23
24
Named Routes
25
Route Prefixes
26
Controllers
Instead of defining all of your request handling logic as
Closures in route files, you may wish to organize this
behavior using Controller classes. Controllers can group
related request handling logic into a single class.
Controllers are stored in the app/http/controllers directory.
Single Action Controllers
27

More Related Content

What's hot (20)

PDF
Spring Framework
NexThoughts Technologies
 
PPTX
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
PDF
Laravel presentation
Toufiq Mahmud
 
PPTX
Terraform 101
Pradeep Loganathan
 
PDF
Apache Sling : JCR, OSGi, Scripting and REST
Carsten Ziegeler
 
PPTX
Swagger APIs for Humans and Robots (Gluecon)
Tony Tam
 
PDF
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
PDF
Spring MVC Framework
Hùng Nguyễn Huy
 
PDF
C# ASP.NET WEB API APPLICATION DEVELOPMENT
Dr. Awase Khirni Syed
 
PPTX
.Net Core - not your daddy's dotnet
Rick van den Bosch
 
PDF
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
PDF
CSS Grid vs. Flexbox
Ecaterina Moraru (Valica)
 
PPSX
CSS Box Model Presentation
Reed Crouch
 
PDF
Functional programming in Scala
datamantra
 
PDF
Python Regular Expressions
KALYAN KS
 
PDF
Java Servlets.pdf
Arumugam90
 
PPTX
React state
Ducat
 
PPTX
Php.ppt
Nidhi mishra
 
PPT
Advanced JavaScript
Stoyan Stefanov
 
Spring Framework
NexThoughts Technologies
 
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
Laravel presentation
Toufiq Mahmud
 
Terraform 101
Pradeep Loganathan
 
Apache Sling : JCR, OSGi, Scripting and REST
Carsten Ziegeler
 
Swagger APIs for Humans and Robots (Gluecon)
Tony Tam
 
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
Spring MVC Framework
Hùng Nguyễn Huy
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
Dr. Awase Khirni Syed
 
.Net Core - not your daddy's dotnet
Rick van den Bosch
 
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
CSS Grid vs. Flexbox
Ecaterina Moraru (Valica)
 
CSS Box Model Presentation
Reed Crouch
 
Functional programming in Scala
datamantra
 
Python Regular Expressions
KALYAN KS
 
Java Servlets.pdf
Arumugam90
 
React state
Ducat
 
Php.ppt
Nidhi mishra
 
Advanced JavaScript
Stoyan Stefanov
 

Similar to Object Oriented Programming with Laravel - Session 2 (20)

PPTX
Laravel 5
Sudip Simkhada
 
PPTX
Laravel overview
Obinna Akunne
 
PDF
Lecture11_LaravelGetStarted_SPring2023.pdf
ShaimaaMohamedGalal
 
PPT
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 
PPTX
What-is-Laravel and introduciton to Laravel
PraveenHegde20
 
PPTX
Laravel
Himani gajjar
 
PDF
Web Development with Laravel 5
Soheil Khodayari
 
ODP
Laravel 5.3 - Web Development Php framework
Swapnil Tripathi ( Looking for new challenges )
 
PPTX
Laravel Tutorial PPT
Piyush Aggarwal
 
PDF
Memphis php 01 22-13 - laravel basics
Joe Ferguson
 
PDF
Laravel 4 presentation
Abu Saleh Muhammad Shaon
 
PDF
Why Laravel?
Jonathan Goode
 
PDF
Laravel Web Development: A Comprehensive Guide
deep9753ak
 
PPTX
Introduction to Laravel Framework (5.2)
Viral Solani
 
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
PPT
Web service with Laravel
Abuzer Firdousi
 
PPTX
Laravel ppt
Mayank Panchal
 
PPTX
laravel.pptx
asif290119
 
PPTX
Laravel Introduction Module 1 Presentation
Raduelico
 
PDF
Web services with laravel
Confiz
 
Laravel 5
Sudip Simkhada
 
Laravel overview
Obinna Akunne
 
Lecture11_LaravelGetStarted_SPring2023.pdf
ShaimaaMohamedGalal
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 
What-is-Laravel and introduciton to Laravel
PraveenHegde20
 
Laravel
Himani gajjar
 
Web Development with Laravel 5
Soheil Khodayari
 
Laravel 5.3 - Web Development Php framework
Swapnil Tripathi ( Looking for new challenges )
 
Laravel Tutorial PPT
Piyush Aggarwal
 
Memphis php 01 22-13 - laravel basics
Joe Ferguson
 
Laravel 4 presentation
Abu Saleh Muhammad Shaon
 
Why Laravel?
Jonathan Goode
 
Laravel Web Development: A Comprehensive Guide
deep9753ak
 
Introduction to Laravel Framework (5.2)
Viral Solani
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
Web service with Laravel
Abuzer Firdousi
 
Laravel ppt
Mayank Panchal
 
laravel.pptx
asif290119
 
Laravel Introduction Module 1 Presentation
Raduelico
 
Web services with laravel
Confiz
 
Ad

More from Shahrzad Peyman (11)

PDF
Web Design & Development - Session 9
Shahrzad Peyman
 
PDF
Web Design & Development - Session 8
Shahrzad Peyman
 
PDF
Web Design & Development - Session 7
Shahrzad Peyman
 
PDF
Web Design & Development - Session 6
Shahrzad Peyman
 
PDF
Web Design & Development - Session 4
Shahrzad Peyman
 
PDF
Web Design & Development - Session 3
Shahrzad Peyman
 
PDF
Web Design & Development - Session 2
Shahrzad Peyman
 
PDF
Web Design & Development - Session 1
Shahrzad Peyman
 
PDF
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
PDF
Object Oriented Programming with Laravel - Session 5
Shahrzad Peyman
 
PDF
Object Oriented Programming with Laravel - Session 4
Shahrzad Peyman
 
Web Design & Development - Session 9
Shahrzad Peyman
 
Web Design & Development - Session 8
Shahrzad Peyman
 
Web Design & Development - Session 7
Shahrzad Peyman
 
Web Design & Development - Session 6
Shahrzad Peyman
 
Web Design & Development - Session 4
Shahrzad Peyman
 
Web Design & Development - Session 3
Shahrzad Peyman
 
Web Design & Development - Session 2
Shahrzad Peyman
 
Web Design & Development - Session 1
Shahrzad Peyman
 
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
Object Oriented Programming with Laravel - Session 5
Shahrzad Peyman
 
Object Oriented Programming with Laravel - Session 4
Shahrzad Peyman
 
Ad

Recently uploaded (20)

PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 

Object Oriented Programming with Laravel - Session 2

  • 2. 2 Today’s Presentation • Encapsulation, Access Level and Inheritance • Local Development Server • Front Controller • Configuration • Directory Structure • The Root Directory • The App Directory • Routing • Controllers
  • 3. Encapsulation • In basic terms, it’s the way we define the visibility of our properties and methods. • When you’re creating classes, you have to ask yourself what properties and methods can be accessed outside of the class. 3
  • 4. Access Levels Specifier Class SubClass all Private * Protected * * Public * * * 4
  • 5. Inheritance • In object-oriented programming, inheritance is when a class is based on another class, using the same implementation or specifying a new implementation to maintain the same behavior. • Such an inherited class is called a subclass of its parent class or super class. 5
  • 8. Local Development Server • If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve artisan command. • This command will start a development server at http://localhost:8000 • Of course, more robust local development options are available via Homestead and Valet. 8
  • 9. Front Controller • Like HTTP itself, the Request and Response objects are pretty simple. The hard part of building an application is writing what comes in between. In other words, the real work comes in writing the code that interprets the request information and creates the response • Your application probably does many things, like sending emails, handling form submissions, saving things to a database, rendering HTML pages and protecting content with security. How can you manage all of this and still keep your code organized and maintainable?
  • 10. Front Controller • Traditionally, applications were built so that each "page" of a site was its own physical file: A. index.php B. contact.php C. blog.php • There are several problems with this approach, including the inflexibility of the URLs (what if you wanted to change blog.php to news.php without breaking all of your links?) and the fact that each file must manually include some set of core files so that security, database connections and the "look" of the site can remain consistent.
  • 11. Front Controller • A much better solution is to use a front controller: a single PHP file that handles every request coming into your application. • Now, every request is handled exactly the same way. Instead of individual URLs executing different PHP files, the front controller is always executed, and the routing of different URLs to different parts of your application is done internally.
  • 12. Configuration Public Directory: After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application. 12
  • 13. Configuration Config Directory: All of the configuration files for the Laravel framework are stored in the config directory. Application Key: The next thing you should do after installing Laravel is set your application key to a random string. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command. 13
  • 14. Configuration Configuration Caching: To give your application a speed boost, you should cache all of your configuration files into a single file using the config:cache Artisan command. This will combine all of the configuration options for your application into a single file which will be loaded quickly by the framework. 14
  • 15. Configuration Maintenance Mode: When your application is in maintenance mode, a custom view will be displayed for all requests into your application. This makes it easy to "disable" your application while it is updating or when you are performing maintenance. To enable maintenance mode, simply execute the down Artisan command: php artisan down. To disable maintenance mode, use the up command. 15
  • 16. Directory Structure The default Laravel application structure is intended to provide a great starting point for both large and small applications. Of course, you are free to organize your application however you like. Where is Models Directory? 16
  • 17. The Root Directory • App • Bootstrap • Config • Database • Public • Resources • Routes • Storage • Tests • Vendor 17
  • 18. 18 The App Directory The majority of your application is housed in the App directory. By default, this directory is namespaced under App and is autoloaded by Composer using the PSR-4 autoloading standard. The App directory contains a variety of additional directories such as Console, Http and Providers. Think of the Console and Http directories as providing an API into the core of your application. The HTTP protocol and CLI are both mechanisms to interact with your application, but do not actually contain application logic.
  • 19. Routing The most basic Laravel routes simply accept a URI and a Closure, providing a very simple and expressive method of defining routes: All Laravel routes are defined in your route files, which are located in the routes directory. 19
  • 23. Global Constraints If you would like a route parameter to always be constrained by a given regular expression, you may use the pattern method. You should define these patterns in the boot method of your RouteServiceProvider: 23
  • 26. 26 Controllers Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. Controllers can group related request handling logic into a single class. Controllers are stored in the app/http/controllers directory.