SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
1
Getting started with
Laravel
Presenter :
Nikhil Agrawal
Mindfire Solutions
Date: 22nd April, 2014
2
Zend PHP 5.3 Certified
OCA-1z0-870 - MySQL 5 Certified
DELF-A1-French Certified
Skills: Laravel, cakePHP, Codeigniter, Mysql, Jquery, HTML,
css
About me
Presenter: Nikhil Agrawal, Mindfire Solutions
Connect Me:
https://www.facebook.com/nkhl.agrawal
http://in.linkedin.com/pub/nikhil-agrawal/33/318/21b/
https://twitter.com/NikhilAgrawal44
Contact Me:
Email: nikhila@mindfiresolutions.com, nikhil_agrawal@live.com
Skype: mfsi_nikhila
3
Content
✔ Introduction
✔ Features
✔ Setup
✔ Artisan CLI
✔ Routing
✔ Controller, Model, View (MVC)
✔ Installing packages
✔ Migration
✔ Error & Logging
✔ References & QA
Presenter: Nikhil Agrawal, Mindfire Solutions
4
Introduction
✔ Started by Taylor Otwell (a c# developer).
✔ PHP V>= 5.3 based MVC framework.
✔ Hugely inspired by other web framework including
frameworks in other language such as ROR,
ASP.NET and Sinatra
✔ Composer-based
✔ Has a command line interface called as Artisan
✔ Current stable version available is 4.1
Presenter: Nikhil Agrawal, Mindfire Solutions
5
Features out-of-the-box
✔ Flexible routing
✔ Powerful ActiveRecord ORM
✔ Migration and seeding
✔ Queue driver
✔ Cache driver
✔ Command-Line Utility (Artisan)
✔ Blade Template
✔ Authentication driver
✔ Pagination, Mail drivers, unit testing and many more
Presenter: Nikhil Agrawal, Mindfire Solutions
6
Setup
✔ Install Composer
curl -sS https://getcomposer.org/installer | php
✔ It is a dependency manager
✔ What problem it solves?
✔ composer.json, composer.lock files
✔ Install laravel / create-project.
✔ Folder structure
✔ Request lifecycle
✔ Configuration
Presenter: Nikhil Agrawal, Mindfire Solutions
7
Artisan
✔ Artisan is a command-line interface tool to speed up
development process
✔ Commands
✔ List all commands : php artisan list
✔ View help for a commands : php artisan help migrate
✔ Start PHP server : php artisan serve
✔ Interact with app : php artisan tinker
✔ View routes : php artisan routes
✔ And many more...
Presenter: Nikhil Agrawal, Mindfire Solutions
8
Routing
✔ Basic Get/Post route
✔ Route with parameter & https
✔ Route to controller action
Route::get('/test', function() {
return 'Hello'
})
Route::get('/test/{id}', array('https', function() {
return 'Hello'
}));
Route::get('/test/{id}', array(
'uses' => 'UsersController@login',
'as' => 'login'
)
)
Presenter: Nikhil Agrawal, Mindfire Solutions
9
Routing cont..
✔ Route group and prefixes
✔ Route Model binding
✔ Url of route:
✔ $url = route('routeName', $param);
✔ $url = action('ControllerName@method', $param)
Route::group(array('before' => 'auth|admin', 'prefix' => 'admin'), function (){
//Different routes
})
Binding a parameter to model
Route::model('user_id', 'User');
Route::get('user/profile/{user_id}', function(User $user){
return $user->firstname . ' ' . $user->lastname
})
Presenter: Nikhil Agrawal, Mindfire Solutions
10
Controller
✔ Extends BaseController, which can be used to write logic
common througout application
✔ RESTful controller
✔ Defining route
Route::controller('users', 'UserController');
✔ Methods name is prefixed with get/post HTTP verbs
✔ Resource controller
✔ Creating using artisan
✔ Register in routes
✔ Start using it
Presenter: Nikhil Agrawal, Mindfire Solutions
11
Model
✔ Model are used to interact with database.
✔ Each model corresponds to a table in db.
✔ Two different ways to write queries
1. Using Query Builder
2. Using Eloquent ORM
Presenter: Nikhil Agrawal, Mindfire Solutions
12
Query Builder (Model)
✔ SELECT
✔
$users = DB::table('users')->get();
✔ INSERT
✔ $id = DB::table('user')
->insertGetId(array('email' =>'nikhila@mindfire.com',
'password' => 'mindfire'));
✔ UPDATE
✔ DB::table('users')
->where('active', '=', 0)
->update(array('active' => 1));
✔ DELETE
✔ DB::table('users')
->delete();
Presenter: Nikhil Agrawal, Mindfire Solutions
13
Eloquent ORM (Model)
✔ Defining a Eloquent model
✔ Class User Extends Eloquent { }
✔ Try to keep the table name plural and the respective model as singular (e.g
users / User)
✔ SELECT
✔ $user = User::find(1) //Using Primary key
✔ $user = User::findorfail(1) //Throws ModelNotFoundException if
no data is found
✔ $user = Menu::where('group', '=', 'admin')->remember(10)->get();
//Caches Query for 10 minutes
✔ INSERT
✔ $user_obj = new User();
$user_obj->name = 'nikhil';
$user_obj->save();
✔ $user = User::create(array('name' => 'nikhil'));
14
Query Scope (Eloquent ORM)
✔ Allow re-use of logic in model.
Presenter: Nikhil Agrawal, Mindfire Solutions
15
Many others Eloquent features..
✔ Defining Relationships
✔ Soft deleting
✔ Mass Assignment
✔ Model events
✔ Model observer
✔ Eager loading
✔ Accessors & Mutators
16
View (Blade Template)
Presenter: Nikhil Agrawal, Mindfire Solutions
17
Loops
View Composer
✔ View composers are callbacks or class methods that are called when
a view is rendered.
✔ If you have data that you want bound to a given view each time that
view is rendered throughout your application, a view composer can
organize that code into a single location
View::composer('displayTags', function($view)
{
$view->with('tags', Tag::all());
});
Presenter: Nikhil Agrawal, Mindfire Solutions
18
Installing packages
✔ Installing a new package:
✔ composer require <packageName> (Press Enter)
✔ Give version information
✔ Using composer.json/composer.lock files
✔ composer install
✔ Some useful packages
✔ Sentry 2 for ACL implementation
✔ bllim/datatables for Datatables
✔ Way/Generators for speedup development process
✔ barryvdh/laravel-debugbar
✔ Check packagist.org for more list of packages
Presenter: Nikhil Agrawal, Mindfire Solutions
19
Migration
Developer A
✔ Generate migration class
✔ Run migration up
✔ Commits file
Developer B
✔ Pull changes from scm
✔ Run migration up
1. Install migration
✔ php artisan migrate install
2. Create migration using
✔ php artisan migrate:make name
3. Run migration
✔ php artisan migrate
4. Refresh, Reset, Rollback migration
Presenter: Nikhil Agrawal, Mindfire Solutions
Steps
20
Error & Logging
✔ Enable/Disable debug error in app/config/app.php
✔ Configure error log in app/start/global.php
✔ Use Daily based log file or on single log file
✔ Handle 404 Error
App::missing(function($exception){
return Response::view('errors.missing');
});
✔ Handling fatal error
App::fatal(function($exception){
return "Fatal Error";
});
✔ Generate HTTP exception using
App:abort(403);
✔ Logging error
✔ Log::warning('Somehting is going wrong'); //Info,error
21
References
● http://laravel.com/docs (Official Documentation)
● https://getcomposer.org/doc/00-intro.md (composer)
● https://laracasts.com/ (Video tutorials)
● http://cheats.jesse-obrien.ca/ (Cheat Sheet)
● http://taylorotwell.com/
Presenter: Nikhil Agrawal, Mindfire Solutions
22
Questions ??
Presenter: Nikhil Agrawal, Mindfire Solutions
23
A Big
Thank you !
Presenter: Nikhil Agrawal, Mindfire Solutions
24
Connect Us @
www.mindfiresolutions.com
https://www.facebook.com/MindfireSolutions
http://www.linkedin.com/company/mindfire-
solutions
http://twitter.com/mindfires

Weitere ähnliche Inhalte

Was ist angesagt?

Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu
 

Was ist angesagt? (20)

ACL in CodeIgniter
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIs
 
Extending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockExtending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh Pollock
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful Code
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
 
Hacking hhvm
Hacking hhvmHacking hhvm
Hacking hhvm
 
Zend framework
Zend frameworkZend framework
Zend framework
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Desenvolvendo APIs usando Rails - Guru SC 2012
Desenvolvendo APIs usando Rails - Guru SC 2012Desenvolvendo APIs usando Rails - Guru SC 2012
Desenvolvendo APIs usando Rails - Guru SC 2012
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 

Andere mochten auch

Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
WEBdeBS
 

Andere mochten auch (20)

Reflection-In-PHP
Reflection-In-PHPReflection-In-PHP
Reflection-In-PHP
 
EuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein RückblickEuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein Rückblick
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
 
Load testing
Load testingLoad testing
Load testing
 
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.py
 
Django-Queryset
Django-QuerysetDjango-Queryset
Django-Queryset
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
PythonBrasil[8] closing
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
Bottle - Python Web Microframework
Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
User-centered open source
User-centered open sourceUser-centered open source
User-centered open source
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & Postgresql
 

Ähnlich wie Getting Started-with-Laravel

What the heck went wrong?
What the heck went wrong?What the heck went wrong?
What the heck went wrong?
Andy McKay
 

Ähnlich wie Getting Started-with-Laravel (20)

SF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James WilliamsSF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Panmind at Ruby Social Club Milano
Panmind at Ruby Social Club MilanoPanmind at Ruby Social Club Milano
Panmind at Ruby Social Club Milano
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with Backstage
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthrough
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Ahmadabad mule soft_meetup_6march2021_azure_CICD
Ahmadabad mule soft_meetup_6march2021_azure_CICDAhmadabad mule soft_meetup_6march2021_azure_CICD
Ahmadabad mule soft_meetup_6march2021_azure_CICD
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016
 
What the heck went wrong?
What the heck went wrong?What the heck went wrong?
What the heck went wrong?
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
 
Sprint 71
Sprint 71Sprint 71
Sprint 71
 
Working with AngularJS
Working with AngularJSWorking with AngularJS
Working with AngularJS
 
Pyramid patterns
Pyramid patternsPyramid patterns
Pyramid patterns
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009
 
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
 
OpenStack Rally presentation by RamaK
OpenStack Rally presentation by RamaKOpenStack Rally presentation by RamaK
OpenStack Rally presentation by RamaK
 
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptxNew features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 

Mehr von Mindfire Solutions

Mehr von Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Kürzlich hochgeladen

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

Getting Started-with-Laravel

  • 1. 1 Getting started with Laravel Presenter : Nikhil Agrawal Mindfire Solutions Date: 22nd April, 2014
  • 2. 2 Zend PHP 5.3 Certified OCA-1z0-870 - MySQL 5 Certified DELF-A1-French Certified Skills: Laravel, cakePHP, Codeigniter, Mysql, Jquery, HTML, css About me Presenter: Nikhil Agrawal, Mindfire Solutions Connect Me: https://www.facebook.com/nkhl.agrawal http://in.linkedin.com/pub/nikhil-agrawal/33/318/21b/ https://twitter.com/NikhilAgrawal44 Contact Me: Email: nikhila@mindfiresolutions.com, nikhil_agrawal@live.com Skype: mfsi_nikhila
  • 3. 3 Content ✔ Introduction ✔ Features ✔ Setup ✔ Artisan CLI ✔ Routing ✔ Controller, Model, View (MVC) ✔ Installing packages ✔ Migration ✔ Error & Logging ✔ References & QA Presenter: Nikhil Agrawal, Mindfire Solutions
  • 4. 4 Introduction ✔ Started by Taylor Otwell (a c# developer). ✔ PHP V>= 5.3 based MVC framework. ✔ Hugely inspired by other web framework including frameworks in other language such as ROR, ASP.NET and Sinatra ✔ Composer-based ✔ Has a command line interface called as Artisan ✔ Current stable version available is 4.1 Presenter: Nikhil Agrawal, Mindfire Solutions
  • 5. 5 Features out-of-the-box ✔ Flexible routing ✔ Powerful ActiveRecord ORM ✔ Migration and seeding ✔ Queue driver ✔ Cache driver ✔ Command-Line Utility (Artisan) ✔ Blade Template ✔ Authentication driver ✔ Pagination, Mail drivers, unit testing and many more Presenter: Nikhil Agrawal, Mindfire Solutions
  • 6. 6 Setup ✔ Install Composer curl -sS https://getcomposer.org/installer | php ✔ It is a dependency manager ✔ What problem it solves? ✔ composer.json, composer.lock files ✔ Install laravel / create-project. ✔ Folder structure ✔ Request lifecycle ✔ Configuration Presenter: Nikhil Agrawal, Mindfire Solutions
  • 7. 7 Artisan ✔ Artisan is a command-line interface tool to speed up development process ✔ Commands ✔ List all commands : php artisan list ✔ View help for a commands : php artisan help migrate ✔ Start PHP server : php artisan serve ✔ Interact with app : php artisan tinker ✔ View routes : php artisan routes ✔ And many more... Presenter: Nikhil Agrawal, Mindfire Solutions
  • 8. 8 Routing ✔ Basic Get/Post route ✔ Route with parameter & https ✔ Route to controller action Route::get('/test', function() { return 'Hello' }) Route::get('/test/{id}', array('https', function() { return 'Hello' })); Route::get('/test/{id}', array( 'uses' => 'UsersController@login', 'as' => 'login' ) ) Presenter: Nikhil Agrawal, Mindfire Solutions
  • 9. 9 Routing cont.. ✔ Route group and prefixes ✔ Route Model binding ✔ Url of route: ✔ $url = route('routeName', $param); ✔ $url = action('ControllerName@method', $param) Route::group(array('before' => 'auth|admin', 'prefix' => 'admin'), function (){ //Different routes }) Binding a parameter to model Route::model('user_id', 'User'); Route::get('user/profile/{user_id}', function(User $user){ return $user->firstname . ' ' . $user->lastname }) Presenter: Nikhil Agrawal, Mindfire Solutions
  • 10. 10 Controller ✔ Extends BaseController, which can be used to write logic common througout application ✔ RESTful controller ✔ Defining route Route::controller('users', 'UserController'); ✔ Methods name is prefixed with get/post HTTP verbs ✔ Resource controller ✔ Creating using artisan ✔ Register in routes ✔ Start using it Presenter: Nikhil Agrawal, Mindfire Solutions
  • 11. 11 Model ✔ Model are used to interact with database. ✔ Each model corresponds to a table in db. ✔ Two different ways to write queries 1. Using Query Builder 2. Using Eloquent ORM Presenter: Nikhil Agrawal, Mindfire Solutions
  • 12. 12 Query Builder (Model) ✔ SELECT ✔ $users = DB::table('users')->get(); ✔ INSERT ✔ $id = DB::table('user') ->insertGetId(array('email' =>'nikhila@mindfire.com', 'password' => 'mindfire')); ✔ UPDATE ✔ DB::table('users') ->where('active', '=', 0) ->update(array('active' => 1)); ✔ DELETE ✔ DB::table('users') ->delete(); Presenter: Nikhil Agrawal, Mindfire Solutions
  • 13. 13 Eloquent ORM (Model) ✔ Defining a Eloquent model ✔ Class User Extends Eloquent { } ✔ Try to keep the table name plural and the respective model as singular (e.g users / User) ✔ SELECT ✔ $user = User::find(1) //Using Primary key ✔ $user = User::findorfail(1) //Throws ModelNotFoundException if no data is found ✔ $user = Menu::where('group', '=', 'admin')->remember(10)->get(); //Caches Query for 10 minutes ✔ INSERT ✔ $user_obj = new User(); $user_obj->name = 'nikhil'; $user_obj->save(); ✔ $user = User::create(array('name' => 'nikhil'));
  • 14. 14 Query Scope (Eloquent ORM) ✔ Allow re-use of logic in model. Presenter: Nikhil Agrawal, Mindfire Solutions
  • 15. 15 Many others Eloquent features.. ✔ Defining Relationships ✔ Soft deleting ✔ Mass Assignment ✔ Model events ✔ Model observer ✔ Eager loading ✔ Accessors & Mutators
  • 16. 16 View (Blade Template) Presenter: Nikhil Agrawal, Mindfire Solutions
  • 17. 17 Loops View Composer ✔ View composers are callbacks or class methods that are called when a view is rendered. ✔ If you have data that you want bound to a given view each time that view is rendered throughout your application, a view composer can organize that code into a single location View::composer('displayTags', function($view) { $view->with('tags', Tag::all()); }); Presenter: Nikhil Agrawal, Mindfire Solutions
  • 18. 18 Installing packages ✔ Installing a new package: ✔ composer require <packageName> (Press Enter) ✔ Give version information ✔ Using composer.json/composer.lock files ✔ composer install ✔ Some useful packages ✔ Sentry 2 for ACL implementation ✔ bllim/datatables for Datatables ✔ Way/Generators for speedup development process ✔ barryvdh/laravel-debugbar ✔ Check packagist.org for more list of packages Presenter: Nikhil Agrawal, Mindfire Solutions
  • 19. 19 Migration Developer A ✔ Generate migration class ✔ Run migration up ✔ Commits file Developer B ✔ Pull changes from scm ✔ Run migration up 1. Install migration ✔ php artisan migrate install 2. Create migration using ✔ php artisan migrate:make name 3. Run migration ✔ php artisan migrate 4. Refresh, Reset, Rollback migration Presenter: Nikhil Agrawal, Mindfire Solutions Steps
  • 20. 20 Error & Logging ✔ Enable/Disable debug error in app/config/app.php ✔ Configure error log in app/start/global.php ✔ Use Daily based log file or on single log file ✔ Handle 404 Error App::missing(function($exception){ return Response::view('errors.missing'); }); ✔ Handling fatal error App::fatal(function($exception){ return "Fatal Error"; }); ✔ Generate HTTP exception using App:abort(403); ✔ Logging error ✔ Log::warning('Somehting is going wrong'); //Info,error
  • 21. 21 References ● http://laravel.com/docs (Official Documentation) ● https://getcomposer.org/doc/00-intro.md (composer) ● https://laracasts.com/ (Video tutorials) ● http://cheats.jesse-obrien.ca/ (Cheat Sheet) ● http://taylorotwell.com/ Presenter: Nikhil Agrawal, Mindfire Solutions
  • 22. 22 Questions ?? Presenter: Nikhil Agrawal, Mindfire Solutions
  • 23. 23 A Big Thank you ! Presenter: Nikhil Agrawal, Mindfire Solutions