laravel雄辩的特殊UUID主键

I have a users table that doesn't use an auto increment primary key, instead it uses a binary uuid primary key. I set up my custom model to interact with my table however, I'm having trouble trying to find records by using ::find() because for a case like this, this uuid needs to searched by using HEX() and UNHEX() mysql functions. How to I override this and have whatever is in ::find() to be hexed. The name of the model is Player.

So if I was to try to find a user with a uuid of 9d823b9eec224cbea10b69bec2c5adef, I cannot find them by doing:

Player::find('9d823b9eec224cbea10b69bec2c5adef') since the uuid needs to be unhexed.

I've tried Player::find("UNHEX('9d823b9eec224cbea10b69bec2c5adef')"); with no results.

Here's my model so far:

class Player extends Eloquent {

    protected $table = 'players';
    protected $connection = 'game';
    protected $primaryKey = 'uuid';

    public $incrementing = false;    
    public $timestamps = false;


}

The datatype for uuid is binary(16)


Update

I've got it to work by using Player::find(DB::raw("UNHEX('9d823b9eec224cbea10b69bec2c5adef')")); however this is a lot to write every time I need to look up a user.

Is there any way I can have the parameter for ::find() always run through DB::raw("UNHEX('uuid')") or be passed through the function hex2bin()?

I am 100% certain I will always be using UUID so I want to override ::find(), not create a new method.

I would try to unhex it in PHP prior to passing it to mysql:

Player::find(hex2bin('9d823b9eec224cbea10b69bec2c5adef'));

You could add this method to your Player class:

public static function findUUID($uuid) {

    return self::find(hex2bin($uuid));

}

Now any where in your project you can call it like:

$result = Player::findUUID('9d823b9eec224cbea10b69bec2c5adef');

If you do not want to declare it statically you can:

public function findUUID($uuid) {

    return self::find(hex2bin($uuid));

}

and then reference it in your code with:

$result = new Player;
$result->findUUID('9d823b9eec224cbea10b69bec2c5adef');

If you really want it like that, you can also do Player::find('9d823b9eec224cbea10b69bec2c5adef') with this

class Player extends Eloquent {

protected $table = 'players';
protected $connection = 'game';
protected $primaryKey = 'uuid';

public $incrementing = false;    
public $timestamps = false;

public static function find($uuid, $columns = array('*')) {
    return self::find("UNHEX('$uuid')", $columns);
}

}

EDITED

added self, as user Elliot Fehr suggested

This should allow you to override the native find() behavior and not have to use findUUID() instead:

protected $primaryKey = 'uuid';

public static function find($uuid)
{
    return parent::find(hex2bin($uuid));
}