-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminController.php
More file actions
71 lines (59 loc) · 2.38 KB
/
AdminController.php
File metadata and controls
71 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Services\Admin\ProviderService;
use App\Services\Admin\ContactFormService;
use App\Services\Admin\EditProfileService;
use App\Http\Requests\Admin\EditProfileRequest;
use App\Http\Requests\Admin\EditProviderRequest;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class AdminController extends Controller
{
public function getProviders()
{
try {
$providers = ProviderService::getAll();
return $this->messageResponse(true, "Providers retrieved successfully", 200, $providers);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve providers", 500);
}
}
public function editProvider(EditProviderRequest $request, $id)
{
try {
ProviderService::editProfile($id, $request->validated());
return $this->messageResponse(true, "Profile updated successfully", 200);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
}
}
public function getContactMessages()
{
try {
$messages = ContactFormService::getAll();
return $this->messageResponse(true, "Messages retrieved successfully", 200, $messages);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve messages", 500);
}
}
public function deleteMessage($id)
{
try {
ContactFormService::delete($id);
return $this->messageResponse(true, "Message deleted successfully", 200);
} catch (ModelNotFoundException $e) {
return $this->errorMessageResponse(false, "ID not Found", $e->getMessage(), 404);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to delete message", 500);
}
}
public function editProfile(EditProfileRequest $request)
{
try {
EditProfileService::editProfile($request->validated());
return $this->messageResponse(true, "Profile updated successfully", 200);
} catch (\Exception $e) {
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to update profile", 500);
}
}
}