Exemple #1
0
App\Classes\Validator::extend('charowner', function ($attribute, $value, $parameters) {
    $character = app('character')->where('id', $value)->first();
    if ($character->account_id != app('account')->auth()->id) {
        return false;
    }
    return true;
});
App\Classes\Validator::extend('charexist', function ($attribute, $value, $parameters) {
    $character = app('character')->where('id', $value)->first();
    if (is_null($character)) {
        return false;
    }
    return true;
});
App\Classes\Validator::extend('noguild', function ($attribute, $value, $parameters) {
    $character = app('character')->where('id', $value)->first();
    if ($character->hasGuild()) {
        return false;
    }
    return true;
});
App\Classes\Validator::extend('minlevel', function ($attribute, $value, $parameters) {
    if (!isset($parameters[0])) {
        throw new Exception('The unique rule not has enough parameters.');
    }
    $character = app('character')->where('id', $value)->first();
    if ($character->level < $parameters[0]) {
        return false;
    }
    return true;
});