Add a command file to Laravel artisan

In order to run a custom command from the command line utility called artisan you need to do two things:

  1. Create a new CustomCommand file
  2. Register that command with artisan

Here’s a sample Command file called FooCommand.php which should be placed in app/commands/ 

<?php

use Illuminate\Console\Command;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputArgument;

class FooCommand extends Command {

/**
 * The console command name.
 *
 * @var string
 */
 protected $name = 'foo:migrate';

/**
 * The console command description.
 *
 * @var string
 */
 protected $description = '';

/**
 * Create a new command instance.
 *
 * @return void
 */
 public function __construct()
 {
 parent::__construct();
 }

/**
 * Execute the console command.
 *
 * @return void
 */
 public function fire()
 {
 $this->info(' Step: 1');
 $this->info(' Cool Stuff Here');

}

}

Then you’ll need to register that in app/start/artisan.php


<?php
/*
 |--------------------------------------------------------------------------
 | Register The Artisan Commands
 |--------------------------------------------------------------------------
 |
 | Each available Artisan command must be registered with the console so
 | that it is available to be called. We'll register every command so
 | the console gets access to each of the command object instances.
 |
 */

Artisan::add(new FooCommand);

Now you can run your command

php artisan foo:migrate

How to set local environment as default in command line (CLI) for Larvel 4 artisan

Typically when Laravel 4 artisan is run from the command line (cli) it uses the production configuration files. This can be changed by using a flag when running the command.

php artisan migrate --env=local

However, adding –env-=local each time while running a script can slow down development. I would recommend adding your development environment hostname to the config file.

To do this Laravel 4 needs the hostname for your development environment. I recommended using a new file called check.php with the following contents:

#!/usr/bin/env php
<?php
     var_dump(gethostname());

Run it from the command line:

php check.php

This will output something like:

string(6) "ubuntu"

In this case ubuntu is what is needed. We’ll need to add it to the environment array in bootstrap/start.php

$env = $app->detectEnvironment(array(

'local' => array('*.local','ubuntu'),

));

Now artisan should run with the local environment as default when run on that machine.

How to add a library folder to Laravel 4

I typically use a library folder in my projects to group of files that you want to use in different projects but don’t want to use Satis to manage the contained files. This folder could also be a helper folder for functions that are static and are mainly generic helpers but don’t quite fit in a model. So in this example I’ll be adding a library folder and have it autoloaded by Laravel. The process for a helpers folder is the same, just replace library with helpers.

First step is to create the folder. (I assume you’re already in laravel project.)

cd app/

mkdir library

cd library

Now we need to add the folder to the autoload file. We will return to laravel project root and view the composer file.

cd ..

vim composer.json

Should look something like.

{
 "require": {
 "laravel/framework": "4.0.*"
 },
 "autoload": {
 "classmap": [
 "app/commands",
 "app/controllers",
 "app/models",
 "app/database/migrations",
 "app/tests/TestCase.php"
 ]
 },
 "minimum-stability": "dev"
 }

We’re going to add the library directory.

{
 "require": {
 "laravel/framework": "4.0.*"
 },
 "autoload": {
 "classmap": [
 "app/commands",
 "app/controllers",
 "app/library", /* Added here */
 "app/models",
 "app/database/migrations",
 "app/tests/TestCase.php"
 ]
 },
 "minimum-stability": "dev"
 }

Let’s reload the autoload. (Assuming composer is an alias.)

composer dump-autoload

Now you can use the library folder.

VMWare Fusion 5 Set Static IP Address

I previously posted on setting a static ip address in vmware fusion 4. This also still works for VMWare Fusion 5.

Steps are the same.

First on your linux vm in terminal run the following command

ifconfig

Then copy the HWaddr it varies from vm to vm so you need to get yours

Link encap:Ethernet  HWaddr 00:0c:29:f4:13:e4

Next edit the dhcp.conf file on your mac

sudo vim /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

After the

####### VMNET DHCP Configuration. End of “DO NOT MODIFY SECTION” #######

Add your new configuration, replace “vmnamehere” with the name of your vm.

host vmnamehere {
hardware ethernet 00:0c:22:f6:11:e8;
fixed-address 192.168.115.50;
}

Now reboot your Mac or, as @splintax mentioned in the comments, restart DHCP.

cd /Applications/VMware Fusion.app/Contents/Library
sudo ./vmnet-cli –configure
sudo ./vmnet-cli –stop
sudo ./vmnet-cli –start

Your vm’s ip address should be what you set.

If that doesn’t work, you may need to remove the network adapter and then re-add it. Make sure that your network adapter is connected to the virtual machine by removing and re-adding it.

  1. Shut down your virtual machine.
  2. In Fusion, go to Virtual Machine > Settings > Network Adapter (Fusion 4 and later) / Network (Fusion 3 and earlier).
  3. Ensure that the network adapter is connected (that is, Enable Network Adapter is ON or the Connected box is selected).
  4. Ensure that the network adapter is configured for NAT or Bridged, and not Host Only or Custom. Make a note of your setting.
  5. Click triangle beside Advanced options and select Remove Network Adapter (Fusion 4 and later) or click the – (minus) button at the bottom of the Network pane (Fusion 3 and earlier) to remove your current network adapter.
  6. From the Settings pane select Add Device > Network Adapter (Fusion 4 and later) or the + (plus) button at the bottom of the Network pane to re-add your network adapter.
  7. Verify that your new network adapter settings match your old settings.
  8. Restart your Mac.
  9. Turn on your virtual machine.

From step 12

Setup an alias in Linux

Setting up an alias in linux is very easy and very helpful. It allows you to determine a short phrase for running a longer command. Or change a common typo to the command you meant.

Here’s an example alias:

$ alias lsl=”ls -la”

This maps lsl to the command ls -la which is half the length and since that’s a common command that’ll help out.

Another example

$ alias h=’history’

This shows the history of the terminal session.