updade and fix service and request for create user
This commit is contained in:
@@ -22,7 +22,7 @@ class PanjareVahedController extends Controller
|
||||
public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse
|
||||
{
|
||||
$iv = config('harim_web_services.Harim_Info.iv');
|
||||
$keyString = config('harim_web_services.Harim_Info.keyString');
|
||||
$keyString = config('harim_web_services.Harim_Info.key');
|
||||
|
||||
$key = hash('sha256',$keyString, true);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Throwable;
|
||||
|
||||
class UserManagementController extends Controller
|
||||
{
|
||||
@@ -38,7 +39,7 @@ class UserManagementController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request): jsonResponse
|
||||
public function limitStore(StoreRequest $request): jsonResponse
|
||||
{
|
||||
auth()->user()->addActivityComplete(1039);
|
||||
|
||||
@@ -53,17 +54,20 @@ class UserManagementController extends Controller
|
||||
'edarate_ostani_id' => $request->edarate_ostani_id,
|
||||
'edarate_ostani_name' => $request->edarate_ostani_id == null ?
|
||||
null :
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id),
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id)->name_fa,
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
'edarate_shahri_name' => $request->edarate_shahri_id == null ?
|
||||
null :
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id),
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id)->name_fa,
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function storeExtra(StoreRequest $request): jsonResponse
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function fullStore(StoreRequest $request): jsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request) {
|
||||
auth()->user()->addActivityComplete(1039);
|
||||
@@ -79,11 +83,11 @@ class UserManagementController extends Controller
|
||||
'edarate_ostani_id' => $request->edarate_ostani_id,
|
||||
'edarate_ostani_name' => $request->edarate_ostani_id == null ?
|
||||
null :
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id),
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id)->name_fa,
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
'edarate_shahri_name' => $request->edarate_shahri_id == null ?
|
||||
null :
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id),
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id)->name_fa,
|
||||
'first_name' => $request->first_name,
|
||||
'last_name' => $request->last_name,
|
||||
'position' => $request->position,
|
||||
@@ -91,6 +95,7 @@ class UserManagementController extends Controller
|
||||
'degree' => $request->degree,
|
||||
'major' => $request->major,
|
||||
]);
|
||||
|
||||
$user->avatar = $request->has('avatar') ?
|
||||
FileFacade::save($request->avatar, "user/{$user->id}") :
|
||||
null;
|
||||
@@ -101,11 +106,22 @@ class UserManagementController extends Controller
|
||||
|
||||
public function show(User $user): JsonResponse
|
||||
{
|
||||
return $this->successResponse($user->with(['roles', 'permissions'])->get());
|
||||
return $this->successResponse($user);
|
||||
}
|
||||
|
||||
public function userPermissions(User $user): JsonResponse
|
||||
{
|
||||
$role = $user->roles()->pluck('name')->first();
|
||||
$permissions = $user->getAllPermissions()->pluck('name');
|
||||
|
||||
return $this->successResponse([
|
||||
'role' => $role,
|
||||
'permissions' => $permissions,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Throwable
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function update(UpdateRequest $request, User $user): JsonResponse
|
||||
{
|
||||
@@ -122,11 +138,11 @@ class UserManagementController extends Controller
|
||||
'edarate_ostani_id' => $request->edarate_ostani_id,
|
||||
'edarate_ostani_name' => $request->edarate_ostani_id == null ?
|
||||
null :
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id),
|
||||
EdarateOstani::query()->find($request->edarate_ostani_id)->name_fa,
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
'edarate_shahri_name' => $request->edarate_shahri_id == null ?
|
||||
null :
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id),
|
||||
EdarateShahri::query()->find($request->edarate_shahri_id)->name_fa,
|
||||
'first_name' => $request->first_name,
|
||||
'last_name' => $request->last_name,
|
||||
'position' => $request->position,
|
||||
@@ -139,7 +155,7 @@ class UserManagementController extends Controller
|
||||
if ($user->avatar) {
|
||||
FileFacade::delete($user->avatar, true);
|
||||
}
|
||||
$data['avatar'] = FileFacade::save($request->file('avatar'), "avatar/{$user->id}/");
|
||||
$data['avatar'] = FileFacade::save($request->file('avatar'), "avatars/{$user->id}/");
|
||||
}
|
||||
|
||||
$user->update($data);
|
||||
@@ -148,15 +164,15 @@ class UserManagementController extends Controller
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function destroy(User $user): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($user) {
|
||||
if ($user->avatar) {
|
||||
FileFacade::delete($user->avatar, true);
|
||||
}
|
||||
if ($user->photo) {
|
||||
FileFacade::delete($user->photo, true);
|
||||
}
|
||||
|
||||
$user->roles()->detach();
|
||||
$user->permissions()->detach();
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Requests\V3\Dashboard\UserManagement;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreExrtraRequest extends FormRequest
|
||||
{
|
||||
@@ -23,17 +24,29 @@ class StoreExrtraRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'edarate_ostani_id' => 'nullable|exists:edarate_ostanis,id|required_without:edarate_shahri_id',
|
||||
'edarate_shahri_id' => 'nullable|exists:edarate_shahris,id|required_without:edarate_ostani_id',
|
||||
'edarate_ostani_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_ostani', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_shahri_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_shahri_id'))),
|
||||
],
|
||||
'edarate_shahri_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_shahri', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_ostani_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_ostani_id'))),
|
||||
],
|
||||
'province_id' => 'required|exists:provinces,id',
|
||||
'city_id' => 'exists:cities,id',
|
||||
'username' => 'required|unique:users,username',
|
||||
'national_code' => 'unique:users,national_code',
|
||||
'password' => 'required|string|confirmed|min:8',
|
||||
'national_code' => 'unique:users,national_code|digits:10',
|
||||
'password' => 'required|confirmed|min:8',
|
||||
'first_name' => 'required|string',
|
||||
'last_name' => 'required|string',
|
||||
'position' => 'string',
|
||||
'mobile' => 'required|string',
|
||||
'mobile' => 'required|regex:/^09\d{9}$/|numeric|digits:11',
|
||||
'degree' => 'string',
|
||||
'major' => 'string',
|
||||
'avatar' => 'required|file|mimes:pdf,jpg,jpeg,png',
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Requests\V3\Dashboard\UserManagement;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
@@ -23,13 +24,25 @@ class StoreRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'edarate_ostani_id' => 'nullable|exists:edarate_ostanis,id|required_without:edarate_shahri_id',
|
||||
'edarate_shahri_id' => 'nullable|exists:edarate_shahris,id|required_without:edarate_ostani_id',
|
||||
'edarate_ostani_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_ostani', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_shahri_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_shahri_id'))),
|
||||
],
|
||||
'edarate_shahri_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_shahri', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_ostani_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_ostani_id'))),
|
||||
],
|
||||
'province_id' => 'required|exists:provinces,id',
|
||||
'city_id' => 'exists:cities,id',
|
||||
'username' => 'required|unique:users,username',
|
||||
'national_code' => 'unique:users,national_code',
|
||||
'password' => 'required|string|confirmed|min:8',
|
||||
'national_code' => 'unique:users,national_code|digits:10',
|
||||
'password' => 'required|confirmed|min:8',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,21 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'province_id' => 'required|exists:provinces,id',
|
||||
'edarate_ostani_id' => 'nullable|exists:edarate_ostanis,id|required_without:edarate_shahri_id',
|
||||
'edarate_shahri_id' => 'nullable|exists:edarate_shahris,id|required_without:edarate_ostani_id', 'city_id' => 'exists:cities,id',
|
||||
'edarate_ostani_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_ostani', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_shahri_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_shahri_id'))),
|
||||
],
|
||||
'edarate_shahri_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('edarate_shahri', 'id'),
|
||||
Rule::prohibitedIf(fn () => filled($this->input('edarate_ostani_id'))),
|
||||
Rule::requiredIf(fn () => blank($this->input('edarate_ostani_id'))),
|
||||
],
|
||||
'city_id' => 'exists:cities,id',
|
||||
'username' => [Rule::unique('users', 'username')->ignore($this->user->id)],
|
||||
'national_code' => ['required', Rule::unique('users', 'national_code')->ignore($this->user->id)],
|
||||
'first_name' => 'required|string',
|
||||
|
||||
Reference in New Issue
Block a user