This commit is contained in:
root committed 2026-05-11 17:58:21 +00:00
1 parent b03c1d4619
commit b07423aef3
42 files changed
+1431 -394

No files matched your search

@@ -14,7 +14,7 @@ class AdminOperatorController extends Controller
public function index()
{
$operators = User::where('role', 'operator')
->with('assignedLot')
->with('assignedLots')
->orderBy('name')
->get();
@@ -26,24 +26,26 @@ class AdminOperatorController extends Controller
public function store(Request $request)
{
$data = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email',
'phone' => 'nullable|string|max:20',
'password' => ['required', Password::min(8)],
'parking_lot_id' => 'nullable|exists:parking_lots,id',
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email',
'phone' => 'nullable|string|max:20',
'password' => ['required', Password::min(8)],
'lot_ids' => 'nullable|array',
'lot_ids.*'=> 'exists:parking_lots,id',
], [
'email.unique' => 'هذا البريد الإلكتروني مستخدم بالفعل.',
]);
User::create([
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'] ?? null,
'password' => Hash::make($data['password']),
'role' => 'operator',
'parking_lot_id' => $data['parking_lot_id'] ?? null,
$operator = User::create([
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'] ?? null,
'password' => Hash::make($data['password']),
'role' => 'operator',
]);
$operator->assignedLots()->sync($data['lot_ids'] ?? []);
return response()->json(['success' => true, 'message' => 'تم إنشاء حساب المشغّل بنجاح.']);
}
@@ -54,20 +56,20 @@ class AdminOperatorController extends Controller
}
$data = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email,' . $operator->id,
'phone' => 'nullable|string|max:20',
'password' => ['nullable', Password::min(8)],
'parking_lot_id' => 'nullable|exists:parking_lots,id',
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email,' . $operator->id,
'phone' => 'nullable|string|max:20',
'password' => ['nullable', Password::min(8)],
'lot_ids' => 'nullable|array',
'lot_ids.*'=> 'exists:parking_lots,id',
], [
'email.unique' => 'هذا البريد الإلكتروني مستخدم بالفعل.',
]);
$updates = [
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'] ?? null,
'parking_lot_id' => $data['parking_lot_id'] ?? null,
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'] ?? null,
];
if (!empty($data['password'])) {
@@ -75,6 +77,7 @@ class AdminOperatorController extends Controller
}
$operator->update($updates);
$operator->assignedLots()->sync($data['lot_ids'] ?? []);
return response()->json(['success' => true, 'message' => 'تم تحديث بيانات المشغّل.']);
}