3
3
namespace App \Http \Controllers \Backend ;
4
4
5
5
use App \Http \Controllers \Controller ;
6
- use App \Mail \Appoinment ;
7
6
use App \Models \AppointmentTime ;
8
7
use App \Models \Calendar ;
9
8
use App \Models \UserAppointment ;
10
9
use App \Notifications \AppointmentApprovedNotification ;
11
10
use Carbon \Carbon ;
11
+ use Illuminate \Database \Eloquent \Builder ;
12
12
use Illuminate \Http \Request ;
13
13
use Illuminate \Support \Facades \Notification ;
14
14
15
15
class UserAppointmentController extends Controller
16
16
{
17
17
public function index ()
18
18
{
19
- $ appointments = UserAppointment::where ('is_approved ' , false )->with ('map ' , 'user ' )->latest ()->latest ()->paginate (paginateCount ());
19
+ $ expert = auth ()->user ()->expertProfile ;
20
+ $ appointments = UserAppointment::where ('is_approved ' , false )
21
+ ->where (function (Builder $ q ) use ($ expert ) {
22
+ if (request ('type ' ) == 'consultation ' ) {
23
+ $ q ->whereNotNull ('expert_profile_id ' );
24
+ if ($ expert != null ) {
25
+ $ q ->where ('expert_profile_id ' , $ expert ->id );
26
+ }
27
+ }
28
+ })
29
+ ->with ('map ' , 'user ' )->latest ()->paginate (paginateCount ());
20
30
$ apt = $ appointments ->first ();
21
31
22
32
return view ('backend.user.appointments ' , compact ('appointments ' ));
23
33
}
24
34
public function times ()
25
35
{
26
- $ times = AppointmentTime::get ();
36
+ $ times = AppointmentTime::where ( ' user_id ' , auth ()-> id ())-> get ();
27
37
28
38
return view ('backend.user.appointment-times ' , compact ('times ' ));
29
39
}
@@ -54,21 +64,50 @@ public function timeDelete(AppointmentTime $time)
54
64
55
65
public function approvedList ()
56
66
{
57
- $ appointments = UserAppointment::where (['is_approved ' => true , 'is_completed ' => false ])->with ('map ' , 'user ' )->latest ('updated_at ' )->latest ()->get ();
67
+ $ expert = auth ()->user ()->expertProfile ;
68
+ $ appointments = UserAppointment::where (['is_approved ' => true , 'is_completed ' => false ])
69
+ ->where (function (Builder $ q ) use ($ expert ) {
70
+ if (request ('type ' ) == 'consultation ' ) {
71
+ $ q ->whereNotNull ('expert_profile_id ' );
72
+ if ($ expert != null ) {
73
+ $ q ->where ('expert_profile_id ' , $ expert ->id );
74
+ }
75
+ }
76
+ })
77
+ ->with ('map ' , 'user ' )->latest ('approved_at ' )->get ();
58
78
59
79
return view ('backend.user.appointmentsApproved ' , compact ('appointments ' ));
60
80
}
61
81
62
82
public function completedList ()
63
83
{
64
- $ appointments = UserAppointment::where (['is_completed ' => true ])->with ('map ' , 'user ' )->latest ('completed_at ' )->latest ()->get ();
84
+ $ expert = auth ()->user ()->expertProfile ;
85
+ $ appointments = UserAppointment::where (['is_completed ' => true ])
86
+ ->where (function (Builder $ q ) use ($ expert ) {
87
+ if (request ('type ' ) == 'consultation ' ) {
88
+ $ q ->whereNotNull ('expert_profile_id ' );
89
+ if ($ expert != null ) {
90
+ $ q ->where ('expert_profile_id ' , $ expert ->id );
91
+ }
92
+ }
93
+ })
94
+ ->with ('map ' , 'user ' )->latest ('completed_at ' )->get ();
65
95
66
96
return view ('backend.user.appointmentsCompleted ' , compact ('appointments ' ));
67
97
}
68
98
69
99
public function approve (int $ id )
70
100
{
71
101
$ appointment = UserAppointment::find ($ id );
102
+ if ($ appointment ->expert_profile_id != null ) {
103
+ $ expert = auth ()->user ()->expertProfile ;
104
+ if ($ expert != null && $ appointment ->expert_profile_id != $ expert ->id ) {
105
+ return back ()->with ([
106
+ 'alert-type ' => 'warning ' ,
107
+ 'message ' => 'This consultation does not belong to you! '
108
+ ]);
109
+ }
110
+ }
72
111
$ appointment ->is_approved = true ;
73
112
$ appointment ->update ();
74
113
Calendar::create ([
@@ -91,6 +130,15 @@ public function approve(int $id)
91
130
public function complete (int $ id )
92
131
{
93
132
$ appointment = UserAppointment::find ($ id );
133
+ if ($ appointment ->expert_profile_id != null ) {
134
+ $ expert = auth ()->user ()->expertProfile ;
135
+ if ($ expert != null && $ appointment ->expert_profile_id != $ expert ->id ) {
136
+ return back ()->with ([
137
+ 'alert-type ' => 'warning ' ,
138
+ 'message ' => 'This consultation does not belong to you! '
139
+ ]);
140
+ }
141
+ }
94
142
$ appointment ->is_completed = true ;
95
143
$ appointment ->completed_at = now ();
96
144
$ appointment ->update ();
@@ -113,6 +161,15 @@ public function complete(int $id)
113
161
public function destroy (int $ id )
114
162
{
115
163
$ appointment = UserAppointment::find ($ id );
164
+ if ($ appointment ->expert_profile_id != null ) {
165
+ $ expert = auth ()->user ()->expertProfile ;
166
+ if ($ expert != null && $ appointment ->expert_profile_id != $ expert ->id ) {
167
+ return back ()->with ([
168
+ 'alert-type ' => 'warning ' ,
169
+ 'message ' => 'This consultation does not belong to you! '
170
+ ]);
171
+ }
172
+ }
116
173
$ appointment ->delete ();
117
174
$ alert = [
118
175
'message ' => 'Appointment Deleted ' ,
0 commit comments