Laravel 5 Elixir Gulp LiveReload

If you are anything like me, you are having trouble getting LiveReload to work in the Elixir overlay for Gulp. Good news is, I’ve finally got it figured out and am here to share. It turns out to be really simple, you just need to create an extension for Elixir. Add this to your gulpfile.js:

Then in your HTML, include this line:

One thing you will notice is in the livereload.changed()  method, I’m passing the word localhost. If you do not pass something there (for whatever reason), you will get an error like this:

It seems to work fine with an asterisk passed there as well. Maybe somebody can comment further what should go there.

PDO Query Nuance: UPDATE WHERE IN Only Updates One Row

I prefer to always use parameterized queries in PDO when possible. Just now, I encountered a situation in which the complications of using them would have not even been worth it. Take a look at this query:

Given that the post_id‘s exist, this will set a deleted flag on all of them right? Ok, let’s try to define that query using PDO and prepared statements…

As it turns out, that will ONLY update the first row. Turns out, the IN clause is a little more complicated than I thought with prepared statements. There is a proposed solution here, but in my case, the data is not user input and can thus sanitize it myself.

Laravel 4 Session Not Persisting

I pulled out my hair trying to get sessions to persist in Laravel 4 for quite a while. I combed over my code a hundred times and Googled until my eyes bled trying to figure it out. This was my test:

As it turns out, it had to do with my Session configuration in config/session.php. I set my cookie name to something like this:

The lesson here is DO NOT PUT PUNCTUATION IN YOUR COOKIE NAME! Once I removed the period from that cookie name, everything worked fine.

Hope that helps!

OpenCart Dashboard Errors

Have you installed OpenCart and received the following error on the admin dashboard followed by a whole bunch of other issues?

PHP Warning: fopen(/Users/username/Sites/opencart/image/test): failed to open stream: Permission denied in /Users/username/Sites/opencart/admin/controller/common/home.php on line 48

This can be caused by a whole slew of issues. The first thing to try is make sure the folders are writable, typically using the chmod command. From my research in trying to solve my own problem, this is the answer most people give and there are a lot of people it doesn’t help. Here is the solution I found:

1) Find out what user group Apache runs under. For me, it is running in the _www group:

2) Figure out where your main web folder is located. In my example above, I call mine “Sites” on MacOS X but for many it’s called “htdocs” or something else. You should know where your web files go. Open a command line and go to that folder:

3) If you execute an ls -la in the folder, you will most likely see that the group is not the same group as Apache runs under. On Mac, my folders were owned by the “staff” group. We need to change all the files in your web folder to be owned by the same group as Apache executes under:

Of course, replace _www with the group you received in step #1.

Now go back into your OpenCart Dashboard and you shouldn’t have anymore errors.

Install PHP mcrypt in MacOSX

I struggled with installing the mcrypt extension on “Mountain Lion” for a while so I’m posting this to help others.

1) Install HomeBrew:

2) Tap into this in the command line:

3) Install it:

NOTE: If it complains about not having zlib, you need to do this first:

Then it should install successfully.