Getting Started With Laravel 4, Chapter 6: A Command-line Companion Called Artisan

Keeping up with the latest changes

Run composer update to pull the latest changes into your local environment.  Running php artisan changes will show the latest changes.  This is a good way to see new features without having to be constantly checking git, blogs and the like to see new things. 
This did not work on my 5.xxx Laravel install.  I fear it is deprecated now. 
You can also check which version of Laravel you are using with --version

Inspecting and interacting with your application

Using the routes options with show all the routes your application will respond to.  This is a great way to start familiarizing yourself with a new application that someone else has written.

Fiddling with the internals

php artisan tinker This will start an interactive shell called Read-Eval-Print Loop (REPL).  This works much like the regular php shell. 

Turning the engine off

-down command will turn off your app, in case you need to some kind of lengthy maintenance.  This will help to prevent users from seeing an error messages that might happen when you are working with database changes, or large code changes.

-up  Will turn the Laravel engine back on, and allow users to interact with your app.

Finetuning your application

optimize command will trim and merge many classes into a single file.  This has the potential to speed up your app.

Installing third-party commands

You can create your own artisan commands.  The Laravel community has created many of these commands.  Always be careful running any commands you have not verified.  While many people will help to verify commands, it is always possible that a nefarious actor could get a command in there before someone finds it out.

Speeding up your workflow with generatots

One such community script, is the way/generators.  These generators will create all the right files in the right place, assuming you provide the right inputs.

Generating migrations

generate:migration can be used to automatically generate the migration files.  Use the following naming convention
  • create or add to create a new table
  • add or insert to add a field
  • remove, drop or delete will remove a column

Generating HTML forms

You can use generate:form model_name t o generate an HTML form from a model.  You will probably need to tweak it some, but at least it will give you a good starting point.

Generating everything else

Everything else is easy and straightforward to use.  Visit Jeffery Way's Github to see all the options available.

Deploying with a single command

You can use Rocketeer to deploy your new app with one command

Links:
http://rocketeer.autopergamene.eu/

Deployment, the old-school way

You can also deploy via FTP.  This can take some time to deploy.  You can use laravel-vendor-cleanup package to remove all the tests from the vendor directory.  This will make your deploy much smaller. 
One thing that the author did not mention was using GIT to do your deployments.  This is another good way to deploy your app.  There are other newer ways to do continuous deployment.

Rolling out your own artisan commands

We are going to write our own artisan command.  This will extend Symfony's console component.

Links:
http://symfony.com/doc/current/console.html

Creating the command

You have to create the command and then register it.

The anatomy of the command

The command:make will generate the boiler plate code you need to start your own command.  There is a fire() function that will run when you run a particular command.  The last two methods getArguments() and getOptions()  Options on the command line are prefaced with double dashes (--).  $this->argument and $this->options are how you get the arguments and options from the command line.

Writing the command

This is a straight forward way of writing php commands.  Put all your stuff in functions, and call those functions from the fire()

Comments

Popular posts from this blog

Go Programming Blueprints, Chapter 2, Adding User Accounts

Successful Big Game Hunting Chapter 10