mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 20:41:07 +03:30
Come BackEnd
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user