clrghouz/app/Http/Requests/UserRequest.php
Deon George e7821d4c80
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 38s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m51s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Fix for user creation
2024-06-04 19:21:38 +10:00

40 lines
882 B
PHP

<?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()
{
return Gate::any(['admin','update'],$this->route('o'));
}
public function rules(Request $request)
{
if (! $request->isMethod('post'))
return [];
$o = $this->route('o');
return [
'email' => 'required|email|unique:users,email,'.($o?->exists ? $o->id : 0),
'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',
Rule::in($o?->systems->pluck('id')),
],
];
}
}