These days it’s very uncommon for websites to user usernames and most sites just use the user’s email address.

Laravel has many, many very handy packages we can use to quickly get up and running and save us countless hours when developing a website but sometimes they do not do exactly what we want. In this case I relied on a package called Confide by Zizaco, commonly referred to as Zizaco/Confide. It started off pretty great with me having user creation, login, password reminders etc all working within 30 minutes. However, Zizaco/Confide heavily relies on the existance of a username for creating users and logging in. To get around this you will have to extend Zizaco\Confide\UserValidator and override $rules and also extend Zizaco\Confide\EloquentRepository and override the function getUserByEmailOrUsername.

To do this you can create a file in app/controllers with two classes in it and modify app/start/local.php to re-bind the Confide classes to your new ones so the original classes get overridden.



UPDATE: Had to override the function validateIsUnique as well which required me to “use Zizaco\Confide\ConfideUserInterface;” to get it to work. Code fragment updated to reflect the new situation.

If you ever experience the error ERR_INCOMPLETE_CHUNKED_ENCODING in WordPress (you should be able to find this in your Nginx error log) then you should check the following things:

  • Nginx and PHP-FPM should both be run as the same user
  • The directory /var/lib/nginx and all underlying directories should be chowned to that user

I my case Nginx and PHP-FPM were both running as Apache, but the directory /var/lib/nginx was owned by nginx:root. This meant the dir has to be chowned to apache:apache to fix the problem:

Don’t forget to restart nginx & php-fpm to be on the safe side.

laravelSo I am developing an invoicing system in Laravel and ran into the problem that I couldn’t figure out how to pass validation errors to the master template in Laravel. Normally you can only Redirect::to()->withErrors($validator); and I wasn’t trying to Redirect but output them straight to the View. After having read a few silly solutions which involved View::make()->with(‘errors’, $errors); and then writing a whole new foreach loop in the view instead of the template. That is clearly not an efficient solution since I would mean copy/pasting code from the template to the view.

Doing the following does not work:

So I figured out you can share a variable across all currently loaded views/templates.

Here’s the piece of code that works for me now:

So I get the validator messages and store those in a variable $messages. I then “share” that variable as $errors across all views and my template picks it up in the following piece of code: