2023-08-02 12:42:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
|
|
|
class UserRequest extends FormRequest
|
|
|
|
{
|
|
|
|
public function authorize()
|
|
|
|
{
|
2024-04-25 05:27:45 +00:00
|
|
|
return Gate::any(['admin','update'],$this->route('o'));
|
2023-08-02 12:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rules(Request $request)
|
|
|
|
{
|
|
|
|
if (! $request->isMethod('post'))
|
|
|
|
return [];
|
|
|
|
|
|
|
|
$o = $this->route('o');
|
|
|
|
return [
|
2024-06-04 09:21:38 +00:00
|
|
|
'email' => 'required|email|unique:users,email,'.($o?->exists ? $o->id : 0),
|
2023-08-02 12:42:59 +00:00
|
|
|
'name' => 'required|min:3',
|
|
|
|
'pgp_pubkey' => [
|
|
|
|
'nullable',
|
|
|
|
'min:64',
|
|
|
|
//function ($attribute,$value,$fail) { return $fail('Not this time'); }
|
|
|
|
],
|
|
|
|
'alias' => 'nullable|min:1',
|
|
|
|
'active' => 'required|boolean',
|
|
|
|
'admin' => 'required|boolean',
|
|
|
|
'system_id' => [
|
|
|
|
'nullable',
|
2024-06-04 09:21:38 +00:00
|
|
|
Rule::in($o?->systems->pluck('id')),
|
2023-08-02 12:42:59 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|