mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 23:21:06 +03:30
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use App\User;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
|
|
|
|
|
|
|
|
class StoreUserRequest extends FormRequest
|
|
|
|
{
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
if ($this->method() == 'POST') {
|
|
|
|
return auth('api')->check() && auth('api')->user()->can('store', User::class);
|
|
|
|
} else {
|
|
|
|
$User = $this->route('User');
|
|
|
|
return auth('api')->check() && $User && auth('api')->user()->can('update', $User);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
switch ($this->method()) {
|
|
|
|
case 'POST': {
|
|
|
|
return [
|
|
|
|
'name'=>'required|string|max:255',
|
|
|
|
'cell_number'=>'required|digits_between:10,11|unique:users',
|
|
|
|
'password'=>'required|string|min:6',
|
|
|
|
'medical_center_id' => 'required|numeric|exists:medical_centers,id',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'PUT':
|
|
|
|
case 'PATCH': {
|
|
|
|
$User = $this->route('User');
|
|
|
|
return [
|
|
|
|
'name'=>'required|string|max:255',
|
|
|
|
'cell_number'=>'required|digits_between:10,11|unique:users,id,'.$User->id,
|
|
|
|
'password'=>'required|string|min:6',
|
|
|
|
'medical_center_id' => 'required|numeric|exists:medical_centers,id',
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|