SlideShare a Scribd company logo
1 of 24
Download to read offline
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

More Related Content

What's hot

Continuos integration for iOS projects
Continuos integration for iOS projectsContinuos integration for iOS projects
Continuos integration for iOS projects
Aleksandra Gavrilovska
 

What's hot (18)

Gerrit JavaScript Plugins
Gerrit JavaScript PluginsGerrit JavaScript Plugins
Gerrit JavaScript Plugins
 
Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!
 
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
 
JS performance tools
JS performance toolsJS performance tools
JS performance tools
 
jQuery plugin & testing with Jasmine
jQuery plugin & testing with JasminejQuery plugin & testing with Jasmine
jQuery plugin & testing with Jasmine
 
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
 
Introducing spring
Introducing springIntroducing spring
Introducing spring
 
Test Driven Infrastructure with Docker, Test Kitchen and Serverspec
Test Driven Infrastructure with Docker, Test Kitchen and ServerspecTest Driven Infrastructure with Docker, Test Kitchen and Serverspec
Test Driven Infrastructure with Docker, Test Kitchen and Serverspec
 
Go Revel Gooo...
Go Revel Gooo...Go Revel Gooo...
Go Revel Gooo...
 
Presentation security automation (Selenium Camp)
Presentation security automation (Selenium Camp)Presentation security automation (Selenium Camp)
Presentation security automation (Selenium Camp)
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
Automated Deployments
Automated DeploymentsAutomated Deployments
Automated Deployments
 
Gradle
GradleGradle
Gradle
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Groovy in the Cloud
Groovy in the CloudGroovy in the Cloud
Groovy in the Cloud
 
Continuos integration for iOS projects
Continuos integration for iOS projectsContinuos integration for iOS projects
Continuos integration for iOS projects
 
COSCUP 2020 Google 技術 x 公共參與 x 開源 口罩地圖技術開源
COSCUP 2020 Google 技術 x 公共參與 x 開源 口罩地圖技術開源COSCUP 2020 Google 技術 x 公共參與 x 開源 口罩地圖技術開源
COSCUP 2020 Google 技術 x 公共參與 x 開源 口罩地圖技術開源
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Recently uploaded (20)

Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insights
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 

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