Skip to content

Commit 78c5653

Browse files
committed
add: expert as authenticatble user
1 parent 5725bf0 commit 78c5653

14 files changed

+579
-455
lines changed

app/Http/Controllers/Backend/Map/MapController.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function __construct()
3030
*/
3131
public function index()
3232
{
33-
$maps = Map::paginate(paginateCount());
33+
$user_id = auth()->user()->expertProfile ? auth()->id() : null;
34+
$maps = Map::where('user_id', $user_id)->paginate(paginateCount());
3435
return view('backend.map.showMaps', compact('maps'));
3536
}
3637

@@ -53,7 +54,8 @@ public function store(StoreMapRequest $request)
5354
// dd($src);
5455
$map = Map::create([
5556
...$request->except(['iframe_link']),
56-
'src' => $src
57+
'src' => $src,
58+
'user_id'=> auth()->user()->expertProfile ? auth()->id() : null
5759
]);
5860
$notification = array(
5961
'message' => "Added Successfully",

app/Http/Controllers/Backend/UserAppointmentController.php

+62-5
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@
33
namespace App\Http\Controllers\Backend;
44

55
use App\Http\Controllers\Controller;
6-
use App\Mail\Appoinment;
76
use App\Models\AppointmentTime;
87
use App\Models\Calendar;
98
use App\Models\UserAppointment;
109
use App\Notifications\AppointmentApprovedNotification;
1110
use Carbon\Carbon;
11+
use Illuminate\Database\Eloquent\Builder;
1212
use Illuminate\Http\Request;
1313
use Illuminate\Support\Facades\Notification;
1414

1515
class UserAppointmentController extends Controller
1616
{
1717
public function index()
1818
{
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());
2030
$apt = $appointments->first();
2131

2232
return view('backend.user.appointments', compact('appointments'));
2333
}
2434
public function times()
2535
{
26-
$times = AppointmentTime::get();
36+
$times = AppointmentTime::where('user_id', auth()->id())->get();
2737

2838
return view('backend.user.appointment-times', compact('times'));
2939
}
@@ -54,21 +64,50 @@ public function timeDelete(AppointmentTime $time)
5464

5565
public function approvedList()
5666
{
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();
5878

5979
return view('backend.user.appointmentsApproved', compact('appointments'));
6080
}
6181

6282
public function completedList()
6383
{
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();
6595

6696
return view('backend.user.appointmentsCompleted', compact('appointments'));
6797
}
6898

6999
public function approve(int $id)
70100
{
71101
$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+
}
72111
$appointment->is_approved = true;
73112
$appointment->update();
74113
Calendar::create([
@@ -91,6 +130,15 @@ public function approve(int $id)
91130
public function complete(int $id)
92131
{
93132
$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+
}
94142
$appointment->is_completed = true;
95143
$appointment->completed_at = now();
96144
$appointment->update();
@@ -113,6 +161,15 @@ public function complete(int $id)
113161
public function destroy(int $id)
114162
{
115163
$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+
}
116173
$appointment->delete();
117174
$alert = [
118175
'message' => 'Appointment Deleted',

app/Http/Controllers/ExpertProfileController.php

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function update(UpdateExpertProfileRequest $request, ExpertProfile $exper
110110
{
111111
$expertProfile->name = $request->name;
112112
$expertProfile->post = $request->post;
113+
$expertProfile->user_id = $request->user_id;
113114
$expertProfile->bio = $request->bio;
114115
$expertProfile->district = $request->district;
115116
$expertProfile->thana = $request->thana;

app/Http/Controllers/Frontend/Page/PageController.php

+20-7
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,38 @@ public function clientStudioPage()
4949
}
5050
public function appointmentPage(Request $request, ?ExpertProfile $expertProfile = null)
5151
{
52+
$userId = $expertProfile ? $expertProfile->user_id : User::role('super admin')->first()?->id;
53+
$times = AppointmentTime::where('user_id', $userId)->pluck('time');
5254
$office = !empty($request->query('office_id')) ? Map::find($request->query('office_id')) : null;
5355
if ($office == null) {
54-
$maps = Map::where(function (Builder $q) use ($request) {
56+
$maps = Map::where(function (Builder $q) use ($request, $expertProfile) {
5557
if ($request->query('branch-thana')) {
5658
$q->where('thana', $request->query('branch-thana'));
5759
}
5860
if ($request->query('branch-district')) {
5961
$q->where('district', $request->query('branch-district'));
6062
}
63+
if ($expertProfile != null) {
64+
$q->where('user_id', $expertProfile->user_id);
65+
}
6166
})->latest()->get();
6267
} else {
6368
$maps = [ $office ];
6469
}
65-
$times = AppointmentTime::whereIn('user_id', User::role('super admin')->get()->pluck('id'))->pluck('time');
66-
$branchDistricts = Map::select([ 'district', 'thana' ])->distinct()->latest()->get()->pluck('district');
67-
$branchThanas = Map::select([ 'district', 'thana' ])->distinct()->where(function (Builder $q) use ($request) {
70+
$branchDistricts = Map::select([ 'district', 'thana', 'user_id' ])
71+
->where(function (Builder $q) use ($request, $expertProfile) {
72+
if ($expertProfile != null) {
73+
$q->where('user_id', $expertProfile->user_id);
74+
}
75+
})
76+
->distinct()->latest()->get()->pluck('district');
77+
$branchThanas = Map::select([ 'district', 'thana', 'user_id' ])->distinct()->where(function (Builder $q) use ($request, $expertProfile) {
6878
if (!empty($request->query('branch-district'))) {
6979
$q->where('district', $request->query('branch-district'));
7080
}
81+
if ($expertProfile != null) {
82+
$q->where('user_id', $expertProfile->user_id);
83+
}
7184
})->latest()->get()->pluck('thana');
7285
$banners = getRecords('banners');
7386
$infos1 = Info::where('section_id', 1)->latest()->get();
@@ -76,13 +89,13 @@ public function appointmentPage(Request $request, ?ExpertProfile $expertProfile
7689
}
7790
public function appointmentVirtual(Request $request, ?ExpertProfile $expertProfile = null)
7891
{
92+
$userId = $expertProfile ? $expertProfile->user_id : User::role('super admin')->first()?->id;
93+
$times = AppointmentTime::where('user_id', $userId)->pluck('time');
7994
$office = !empty($request->query('office_id')) ? Map::find($request->query('office_id')) : null;
8095
$banners = getRecords('banners');
81-
$times = AppointmentTime::whereIn('user_id', User::role('super admin')->get()->pluck('id'))->pluck('time');
82-
8396
$infos1 = Info::where('section_id', 1)->latest()->get();
8497
$testimonials = \App\Models\Review::with('user')->latest()->limit(10)->latest()->get();
85-
return view('frontend.pages.appointment.makeAppointmentVirtual', compact('times','banners', 'expertProfile', 'testimonials', 'infos1', 'office'));
98+
return view('frontend.pages.appointment.makeAppointmentVirtual', compact('times', 'banners', 'expertProfile', 'testimonials', 'infos1', 'office'));
8699
}
87100
public function aboutPage()
88101
{

app/Models/ExpertProfile.php

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ class ExpertProfile extends Model
1111
use HasFactory;
1212
protected $guarded = [];
1313

14+
15+
public function owner()
16+
{
17+
return $this->belongsTo(User::class);
18+
}
19+
public function maps()
20+
{
21+
return $this->hasMany(Map::class);
22+
}
23+
1424
function reviews(): MorphMany
1525
{
1626
return $this->morphMany(Review::class, 'reviewable');

database/migrations/2024_06_03_230903_add_user_id_in_expert_profiles_table.php

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public function up(): void
1818
->cascadeOnDelete();
1919

2020
});
21+
Schema::table('maps', function (Blueprint $table) {
22+
$table->foreignId('user_id')
23+
->nullable()
24+
->constrained()
25+
->cascadeOnDelete();
26+
27+
});
2128
}
2229

2330
/**
@@ -31,5 +38,11 @@ public function down(): void
3138
Schema::table('expert_profiles', function (Blueprint $table) {
3239
$table->dropColumn(['user_id']);
3340
});
41+
Schema::table('maps', function (Blueprint $table) {
42+
$table->dropForeign(['user_id']);
43+
});
44+
Schema::table('maps', function (Blueprint $table) {
45+
$table->dropColumn(['user_id']);
46+
});
3447
}
3548
};

0 commit comments

Comments
 (0)