The Watson Validating and the Esensi Model Traits Package traits don’t play nicely with the Felixkiss unique_with Validator Rule. Here’s a quick way to get them working in Laravel 4.

NOTE: A minor change in the underlying code means this technique won’t work for Laravel 5, but I’ve got a fix for that which I’ll be posting shortly.

Trait Directory Setup

  • Create an app/traits directory.
  • Add an "app/traits" entry to the autoload classmap section of the composer.json file in Laravel’s root directory.
  • Run php artisan dump to update the class autoloader.

Watson ValidatingTrait Instructions

If you’re using the Watson ValidatingTrait, then you’ll need to follow these instructions. If you’re using the Esensi ValidatingModelTrait, skip these instructions, and follow the Esensi section below.

  • Copy this gist as app/traits/ValidatingTrait.php

Include this in the Model where you wish to use the ValidatingTrait:

<?php
use \Traits\ValidatingTrait;

instead of:

<?php
use \Watson\Validating\ValidatingTrait;

That’s it, you’re done. You can use the trait and validator together.


Esensi\ValidatingModelTrait Instructions

  • Copy this gist as app/traits/ValidatingModelTrait.php

Include this in the Model where you wish to use the ValidatingModelTrait:

<?php
use \Traits\ValidatingModelTrait;

instead of:

<?php
use \Esensi\Model\Traits\ValidatingModelTrait;

Et voila! They now work together as a team.