SlideShare a Scribd company logo
1 of 21
LARAVEL AND ARTISAN CLI
Sayed Ahmed
Computer Engineering, BUET, Bangladesh
MSc. Computer Science, U of Manitoba, Canada
http://sayed.justetc.net
TOPICS
 Introduction
 Usage
 Common artisan commands
 New artisan commands also come with
packages
 Laravel 4 generators package will be discussed
 How to develop new artisan commands
SHOULD YOU USE THEM
 In general, it’s better to use
 Will make your development faster
 However, you may also consider the aspect
 Just the command is there, do you really need to use
it
 Just because, you can generate something, are you doing
for that or there is a need (business or technical)
 Is there time for it?
 Justify the need, justify the time assigned for the
project, justify budget, justify usefulness, also what is
most important right now
 Use for the benefit; do not use just to use it
 But you need to learn it all
WHAT IS ARTISAN
 A command-line interface
 Comes with Laravel
 Provides helpful commands
 That facilitates rapid application development
 It is driven by the powerful Symfony Console
component
 But Artisan is not that difficult
 If you have to use it, You have to know it for sure,
But knowing is not that difficult. You can just read
and know
 So relax, you will see
LARAVEL - USAGE
 php artisan list
 List all available commands
 php artisan help migrate
 Help screen for the command migrate
 php artisan migrate --env=local
 Run the migrate on local development platform
 php artisan –version
 Artisan version
ARTISAN COMMANDS CAN BE EXTENSION/PACKAGE SPECIFIC
 Install this package, you will get more commands
 https://github.com/JeffreyWay/Laravel-4-Generators
 New generators as we get from the package
 generate:model
 generate:controller
 generate:seed
 generate:view
 generate:migration
 generate:resource
 generate:scaffold
 generate:form
 generate:test
 generate:pivot
LARAVEL-4-GENERATORS COMMANDS
 Related Artisan Commands
 php artisan generate:migration
create_posts_table
 php artisan generate:migration
add_user_id_to_posts_table
LARAVEL-4-GENERATORS ARTISAN COMMANDS
 php artisan generate:migration
create_posts_table --fields="title:string,
body:text“
 php artisan generate:migration
destroy_posts_table
 php artisan generate:migration
destroy_posts_table --fields="title:string,
body:text“
LARAVEL-4-GENERATORS ARTISAN COMMANDS
 php artisan generate:migration
remove_completed_from_tasks_table --
fields="completed:boolean“
 php artisan generate:model Post
 php artisan generate:view dog
 php artisan generate:view index --
path=views/dogs
 php artisan generate:seed dogs
LARAVEL-4-GENERATORS ARTISAN COMMANDS
 php artisan generate:resource dog --
fields="name:string“
 php artisan generate:resource dog --
fields="name:string, age:integer“
 php artisan serve
 php artisan generate:scaffold tweet --
fields="author:string, body:text“
 php artisan generate:form tweet
LARAVEL-4-GENERATORS ARTISAN COMMANDS
 php artisan generate:form tweet --
method="update“
 php artisan generate:form tweet --html="div“
 # copy the output to the clipboard
 php artisan generate:form tweet | pbcopy
 # save it to a form partial php artisan
generate:form tweet >
app/views/posts/form.blade.php
LARAVEL-4-GENERATORS ARTISAN COMMANDS
 php artisan generate:test FooTest
 php artisan generate:pivot posts tags
 php artisan migrate
 php artisan generate:migration
create_posts_table --fields="title:string,
description:text"
 php artisan generate:migration
create_tags_table --fields="name:string"
 php artisan generate:pivot posts tags
DEVELOPING NEW ARTISAN COMMANDS
 By default the commands are in the
app/commands folder
 You can store your commands in other
locations as you want
 However, the location has to autoload by
composer.json settings
DEVELOPING NEW ARTISAN COMMANDS
 php artisan command:make FooCommand
 Create a new command class
 php artisan command:make FooCommand --
path=app/classes --namespace=Classes
 Generate command class in a user provided path
 php artisan command:make AssignUsers --
command=users:assign
 Specify the term to be used from command line
 php artisan command:make AssignUsers --
bench="vendor/package“
 If you need to create the command for a package
INSIDE THE CLASS FOR THE COMMAND
 Name and description properties
 Provide them for help
 Fire method will be triggered
 The getArguments and getOptions
 methods are to accept the command line
parameters for the command to be created
 How options are passed to a command
 php artisan foo --option=bar --option=baz
RETRIEVING OPTIONS AND ARGUMENTS
 Retrieving options and arguments from
command line
 To be used inside your command class
 And then you can process as you want
 $value = $this->option('name');
 $arguments = $this->argument();
CALLING OTHER COMMANDS
 Calling other commands inside from your
commands
 $this->call('command:name', array('argument' =>
'foo', '--option' => 'bar'));
MESSAGE TO THE USER
 After the intended operation, you may want
to display something to the user
 $this->info('Display this on the screen');
 $this->error('Something went wrong!');
ASKING THE USER FOR INFO
 Asking the user for info in between of the
intended operation
 $name = $this->ask('What is your name?');
 $password = $this->secret('What is the
password?');
 $this->confirm($question, true);
REGISTERING COMMANDS
• Once you are done writing your commands
 Done in the app/start/artisan.php
 Use Artisan::add to register the method
 You need to register it
 Artisan::add(new CustomCommand);
 Artisan::resolve('binding.name');
 Artisan::resolve('binding.name');
 Registering A Command That Is In The IoC
Container
REFERENCE
 http://laravel.com/docs/artisan
 https://github.com/JeffreyWay/Laravel-4-
Generators
 http://net.tutsplus.com/tutorials/tools-and-
tips/pro-workflow-in-laravel-and-sublime-text/

More Related Content

What's hot

Build website in_django
Build website in_django Build website in_django
Build website in_django
swee meng ng
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 

What's hot (20)

CakePHP
CakePHPCakePHP
CakePHP
 
Workshop Laravel 5.2
Workshop Laravel 5.2Workshop Laravel 5.2
Workshop Laravel 5.2
 
Rails engines
Rails enginesRails engines
Rails engines
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flask
 
Magento Meetup New Delhi- Console
Magento Meetup New Delhi- ConsoleMagento Meetup New Delhi- Console
Magento Meetup New Delhi- Console
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel 8 events and listeners with example
Laravel 8 events and listeners with exampleLaravel 8 events and listeners with example
Laravel 8 events and listeners with example
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
Wordpress Hacks: When a "Hacker" Becomes a Hero
Wordpress Hacks: When a "Hacker" Becomes a HeroWordpress Hacks: When a "Hacker" Becomes a Hero
Wordpress Hacks: When a "Hacker" Becomes a Hero
 
Play with Alfresco ADF 2.0.0 Angular
Play with Alfresco ADF 2.0.0 AngularPlay with Alfresco ADF 2.0.0 Angular
Play with Alfresco ADF 2.0.0 Angular
 
Build website in_django
Build website in_django Build website in_django
Build website in_django
 
Laravel 101
Laravel 101Laravel 101
Laravel 101
 
Create your own composer package
Create your own composer packageCreate your own composer package
Create your own composer package
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
Creating Perl modules with Dist::Zilla
Creating Perl modules with Dist::ZillaCreating Perl modules with Dist::Zilla
Creating Perl modules with Dist::Zilla
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
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)
 

Viewers also liked

Viewers also liked (6)

EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
EasyEngine - Command-Line tool to manage WordPress Sites on NginxEasyEngine - Command-Line tool to manage WordPress Sites on Nginx
EasyEngine - Command-Line tool to manage WordPress Sites on Nginx
 
WordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngineWordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngine
 
Debugging WordPress Performance using EasyEngine
Debugging WordPress Performance using EasyEngineDebugging WordPress Performance using EasyEngine
Debugging WordPress Performance using EasyEngine
 
Scaling WooCommerce - WordCamp Mumbai 2016
Scaling WooCommerce - WordCamp Mumbai 2016Scaling WooCommerce - WordCamp Mumbai 2016
Scaling WooCommerce - WordCamp Mumbai 2016
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
The Build Trap
The Build TrapThe Build Trap
The Build Trap
 

Similar to Laravel and artisan cli

What is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNTWhat is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNT
Framgia Vietnam
 
Updating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_ServerUpdating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_Server
tutorialsruby
 
Updating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_ServerUpdating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_Server
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 

Similar to Laravel and artisan cli (20)

MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Phalcon 2 - PHP Brazil Conference
Phalcon 2 - PHP Brazil ConferencePhalcon 2 - PHP Brazil Conference
Phalcon 2 - PHP Brazil Conference
 
What is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNTWhat is new in PHP 5.5 - HuyenNT
What is new in PHP 5.5 - HuyenNT
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
Lumen
LumenLumen
Lumen
 
Updating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_ServerUpdating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_Server
 
Updating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_ServerUpdating_PHP_on_OS_X_Server
Updating_PHP_on_OS_X_Server
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Phalcon - Giant Killer
Phalcon - Giant KillerPhalcon - Giant Killer
Phalcon - Giant Killer
 

More from Sayed Ahmed

More from Sayed Ahmed (20)

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
 
Virtualization
VirtualizationVirtualization
Virtualization
 
User interfaces
User interfacesUser interfaces
User interfaces
 
Unreal
UnrealUnreal
Unreal
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Laravel and artisan cli

  • 1. LARAVEL AND ARTISAN CLI Sayed Ahmed Computer Engineering, BUET, Bangladesh MSc. Computer Science, U of Manitoba, Canada http://sayed.justetc.net
  • 2. TOPICS  Introduction  Usage  Common artisan commands  New artisan commands also come with packages  Laravel 4 generators package will be discussed  How to develop new artisan commands
  • 3. SHOULD YOU USE THEM  In general, it’s better to use  Will make your development faster  However, you may also consider the aspect  Just the command is there, do you really need to use it  Just because, you can generate something, are you doing for that or there is a need (business or technical)  Is there time for it?  Justify the need, justify the time assigned for the project, justify budget, justify usefulness, also what is most important right now  Use for the benefit; do not use just to use it  But you need to learn it all
  • 4. WHAT IS ARTISAN  A command-line interface  Comes with Laravel  Provides helpful commands  That facilitates rapid application development  It is driven by the powerful Symfony Console component  But Artisan is not that difficult  If you have to use it, You have to know it for sure, But knowing is not that difficult. You can just read and know  So relax, you will see
  • 5. LARAVEL - USAGE  php artisan list  List all available commands  php artisan help migrate  Help screen for the command migrate  php artisan migrate --env=local  Run the migrate on local development platform  php artisan –version  Artisan version
  • 6. ARTISAN COMMANDS CAN BE EXTENSION/PACKAGE SPECIFIC  Install this package, you will get more commands  https://github.com/JeffreyWay/Laravel-4-Generators  New generators as we get from the package  generate:model  generate:controller  generate:seed  generate:view  generate:migration  generate:resource  generate:scaffold  generate:form  generate:test  generate:pivot
  • 7. LARAVEL-4-GENERATORS COMMANDS  Related Artisan Commands  php artisan generate:migration create_posts_table  php artisan generate:migration add_user_id_to_posts_table
  • 8. LARAVEL-4-GENERATORS ARTISAN COMMANDS  php artisan generate:migration create_posts_table --fields="title:string, body:text“  php artisan generate:migration destroy_posts_table  php artisan generate:migration destroy_posts_table --fields="title:string, body:text“
  • 9. LARAVEL-4-GENERATORS ARTISAN COMMANDS  php artisan generate:migration remove_completed_from_tasks_table -- fields="completed:boolean“  php artisan generate:model Post  php artisan generate:view dog  php artisan generate:view index -- path=views/dogs  php artisan generate:seed dogs
  • 10. LARAVEL-4-GENERATORS ARTISAN COMMANDS  php artisan generate:resource dog -- fields="name:string“  php artisan generate:resource dog -- fields="name:string, age:integer“  php artisan serve  php artisan generate:scaffold tweet -- fields="author:string, body:text“  php artisan generate:form tweet
  • 11. LARAVEL-4-GENERATORS ARTISAN COMMANDS  php artisan generate:form tweet -- method="update“  php artisan generate:form tweet --html="div“  # copy the output to the clipboard  php artisan generate:form tweet | pbcopy  # save it to a form partial php artisan generate:form tweet > app/views/posts/form.blade.php
  • 12. LARAVEL-4-GENERATORS ARTISAN COMMANDS  php artisan generate:test FooTest  php artisan generate:pivot posts tags  php artisan migrate  php artisan generate:migration create_posts_table --fields="title:string, description:text"  php artisan generate:migration create_tags_table --fields="name:string"  php artisan generate:pivot posts tags
  • 13. DEVELOPING NEW ARTISAN COMMANDS  By default the commands are in the app/commands folder  You can store your commands in other locations as you want  However, the location has to autoload by composer.json settings
  • 14. DEVELOPING NEW ARTISAN COMMANDS  php artisan command:make FooCommand  Create a new command class  php artisan command:make FooCommand -- path=app/classes --namespace=Classes  Generate command class in a user provided path  php artisan command:make AssignUsers -- command=users:assign  Specify the term to be used from command line  php artisan command:make AssignUsers -- bench="vendor/package“  If you need to create the command for a package
  • 15. INSIDE THE CLASS FOR THE COMMAND  Name and description properties  Provide them for help  Fire method will be triggered  The getArguments and getOptions  methods are to accept the command line parameters for the command to be created  How options are passed to a command  php artisan foo --option=bar --option=baz
  • 16. RETRIEVING OPTIONS AND ARGUMENTS  Retrieving options and arguments from command line  To be used inside your command class  And then you can process as you want  $value = $this->option('name');  $arguments = $this->argument();
  • 17. CALLING OTHER COMMANDS  Calling other commands inside from your commands  $this->call('command:name', array('argument' => 'foo', '--option' => 'bar'));
  • 18. MESSAGE TO THE USER  After the intended operation, you may want to display something to the user  $this->info('Display this on the screen');  $this->error('Something went wrong!');
  • 19. ASKING THE USER FOR INFO  Asking the user for info in between of the intended operation  $name = $this->ask('What is your name?');  $password = $this->secret('What is the password?');  $this->confirm($question, true);
  • 20. REGISTERING COMMANDS • Once you are done writing your commands  Done in the app/start/artisan.php  Use Artisan::add to register the method  You need to register it  Artisan::add(new CustomCommand);  Artisan::resolve('binding.name');  Artisan::resolve('binding.name');  Registering A Command That Is In The IoC Container
  • 21. REFERENCE  http://laravel.com/docs/artisan  https://github.com/JeffreyWay/Laravel-4- Generators  http://net.tutsplus.com/tutorials/tools-and- tips/pro-workflow-in-laravel-and-sublime-text/