40 lines
1001 B
PHP
40 lines
1001 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
/**
|
|
* 玩家更新请求。
|
|
*
|
|
* @see AdminPlayerUpdateController
|
|
*/
|
|
final class AdminPlayerUpdateRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'username' => ['sometimes', 'string', 'max:128'],
|
|
'nickname' => ['sometimes', 'nullable', 'string', 'max:128'],
|
|
'default_currency' => ['sometimes', 'string', 'max:16', Rule::exists('currencies', 'code')],
|
|
'status' => ['sometimes', 'integer', Rule::in([0, 1, 2])],
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
if (! $this->has('default_currency')) {
|
|
return;
|
|
}
|
|
|
|
$code = strtoupper(substr(trim((string) $this->input('default_currency')), 0, 16));
|
|
$this->merge(['default_currency' => $code]);
|
|
}
|
|
}
|