Tag Archives: PHP

Validating Route Parameters in Laravel 4 Another Way(?)

Note: as the ‘?’ indicates in the title, I’m not sure if this is the “best” way or even a “good” way. But it’s definitely a different way than Laravel’s regular expression route constraints.

I realized recently that I wasn’t doing a good job of validating the route parameters in my Laravel application in my RESTful URIs, so I started working on a solution.

Continue reading

Upgrading to PHP 5.4 on Ubuntu 12.04 LTS

File this under “mostly for my own benefit”, since I often forget how I accomplished something when I need to go back and do it again.

As of March 15, 2013, PHP 5.3.x will only receive “critical fixes” and people are encouraged to upgrade to 5.4 or 5.5. And sometime in 2014, 5.3.x will not longer be supported at all. All of the Linux servers I’m working on now are running Ubuntu 12.04 LTS, which currently provides PHP 5.3.10, so I decided to look into what it takes to update to 5.4.x on these boxes.

It’s simple…
Continue reading

Simple Vagrant config for Laravel updated

Though Vagrant (at least with VirtualBox) appears to be semi-broken at the moment under Mavericks, I’ve updated my simple vagrant config for developing with Laravel as requirements keep growing for different projects: Github

By the way, the temporary fix for the vagrant under Mavericks seems to be running the following:

sudo /Library/StartupItems/VirtualBox/VirtualBox restart

Credit: http://www.stumiller.me/fixing-vagrant-osx-mavericks-update/

Simple SQL query troubleshooting in Laravel 4

A quick tip for seeing a visual representation of your Eloquent/Query Builder queries in Laravel 4, mostly taken from here:

In your App:before filter in filters.php add:

if ( in_array(Config::getEnvironment(), array('local','test')) and (Input::get('sql') !== null) )
 DB::listen(function($sql, $bindings, $time)

I’ve added the logic that first checks to make sure this can only be displayed in the local and test environments, and then if you append ‘?sql’ to the URL, you will see the raw SQL output.

There are other ways to display raw SQL in Laravel 4, including appending ‘->toSql()’ to your Eloquent statements or using a profiling package like this, but I think this is a nice, simple solution.