Laravel so far

Like any developer, aka working product manager, I am often in search of new tools to add to my development tool belt. We’ve all asked and answered the same question, “What is the best product to perform X?”. Answer: “Whichever one you know”. However, no matter what technology is in your tool belt, adding one more is never a bad idea, keeps you current and, most importantly, employable.

With that in mind, I have started learning Laravel as a potential framework for the main application I manage at work. I have tried before, but with limited (and mixed) results. This time, I had no choice as I hired someone to work on a related project and they were familiar with Laravel. I have used CodeIgniter, Kohana and played with Yii, but Laravel has become the framework I hear most about these days. It was time to start learning in earnest.

I decided to start where most folks will, on the installation page. After working my way down the page and selecting to use the Homestead VM, my first roadblock appeared.

From the Laravel Homestead docs page: https://laravel.com/docs/5.2

Via Laravel Installer

First, download the Laravel installer using Composer:

composer global require "laravel/installer"

Make sure to place the ~/.composer/vendor/bin directory (or the equivalent directory for your OS) in your PATH so the laravel executable can be located by your system.

What is not explicitly mentioned, and which I did not clearly understand, is this should be performed on your host machine (Mac in my case). This makes sense since you are not using the Homestead VM for editing, only testing/development. Once this step has completed, you can then run:

laravel new blog

This will create your first Laravel application. This was a much longer set-up than I expected, mostly due to my misunderstanding the documentation.

In my zeal to continue learning about Laravel, I jumped into a “Step by Step guide to building your first Laravel application” by Eric Barnes. Unfortunately, the author also expects you to have understood how the Homestead VM and you host machine are intended to work together. After making some changes to the database file, he tells you:

Save the file and run the migration:

php artisan migrate

I quickly received the following error:

[PDOException]
SQLSTATE[HY000] [2002] Connection refused

Again, I failed to understand this should have been done on the Homestead VM. Why? Simple. The database is hosted on the VM. Any migrations which use the Laravel connection and are set to Localhost need to be done, you know, locally. It was a facepalm moment, thankfully done in the quiet of my office.

In case it helps, this is the MySQL connection array:

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],

You can see I had to change the Database, Username and Password fields from the default Laravel application to those used by Homestead. These are, obviously, for a testing/development environment. You would never publish actual database username and passwords. Once that was all sorted out, I received the expected response:

Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2016_03_08_215310_create_links_table

I was now well on my way.

UPDATE: Mac OS X method for including Composer to bash shell: http://stackoverflow.com/questions/25373188/laravel-installation-how-to-place-the-composer-vendor-bin-directory-in-your