This repository was archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminDashboardController.php
81 lines (66 loc) · 2.67 KB
/
AdminDashboardController.php
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
72
73
74
75
76
77
78
79
80
81
<?php
namespace App\Http\Controllers\Admin\Dashboard;
use App\Http\Controllers\Controller;
use App\Http\Requests\MentorMenteeRequest;
use App\Models\MenteeProfile;
use App\Models\MentorProfile;
use App\Presenters\MenteeProfilePresenter;
use App\Presenters\MentorProfilePresenter;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
class AdminDashboardController extends Controller
{
public function index()
{
$mentorProfiles = MentorProfile::all();
$mentors = $mentorProfiles->map(function ($mentor) {
return MentorProfilePresenter::make($mentor)->all();
});
$menteeProfilesUnpaired = MenteeProfile::doesntHave('mentorProfiles')->get();
$mentees = $menteeProfilesUnpaired->map(function ($mentee) {
return MenteeProfilePresenter::make($mentee)->all();
});
$mentorshipSummary = [];
$menteeMentorProfiles = MenteeProfile::whereHas('mentorProfiles')->get();
foreach ($menteeMentorProfiles as $mentee) {
$menteeUser = $mentee->user;
$summary['menteeFirstName'] = $menteeUser->first_name;
$summary['menteeLastName'] = $menteeUser->last_name;
$summary['menteeEmail'] = $menteeUser->email;
$summary['menteeId'] = $mentee->id;
$pairedmentors = $mentee->mentorProfiles;
foreach ($pairedmentors as $mentor) {
$mentorUser = $mentor->user;
$summary['mentorFirstName'] = $mentorUser->first_name;
$summary['mentorLastName'] = $mentorUser->last_name;
$summary['mentorEmail'] = $mentorUser->email;
$summary['mentorId'] = $mentorUser->id;
$mentorshipSummary[] = $summary;
}
}
return Inertia::render('Admin/Dashboard/Index', [
'mentors' => $mentors,
'mentees' => $mentees,
'summary' => $mentorshipSummary,
]);
}
public function store(MentorMenteeRequest $request)
{
$validated = $request->validated();
$mentor = MentorProfile::findOrFail($validated['mentor_id']);
$mentee = MenteeProfile::findOrFail($validated['mentee_id']);
$mentee->mentorProfiles()->attach($mentor);
return Redirect::route('admin.dashboard.index');
}
public function destroy(MentorMenteeRequest $request)
{
$mentorId = $request->mentor_id;
$menteeId = $request->mentee_id;
if ($mentorId && $menteeId) {
$mentee = MenteeProfile::findOrFail($menteeId);
$mentee->mentorProfiles()->detach();
}
// else error handling
return Redirect::route('admin.dashboard.index');
}
}