From 5a0aab856bb3d218082e0b07d0d5956901771110 Mon Sep 17 00:00:00 2001 From: baghizadizn Date: Fri, 28 Nov 2025 06:56:24 +0000 Subject: [PATCH] fix bug --- app/Http/Controllers/UsersController.php | 22 ++++++- .../InstructorApprovalNotification.php | 62 +++++++++++++++++++ .../vendor/notifications/email.blade.php | 40 +++++++----- 3 files changed, 108 insertions(+), 16 deletions(-) create mode 100644 app/Notifications/InstructorApprovalNotification.php diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 2fdad33..a28a4cd 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -540,12 +540,29 @@ class UsersController extends Controller $application->save(); $user_id = $application->user_id; + // Get the user instance + $user = User::find($user_id); + if (!$user) { + Session::flash('error', get_phrase('User not found')); + return redirect()->back(); + } // Update user role to instructor - User::where('id', $user_id)->update(['role' => 'instructor']); + $user->role = 'instructor'; + $user->save(); // Update instructor status to 1 (active) - Instructors::where('user_id', $user_id)->update(['status' => 1]); + $instructor = Instructors::where('user_id', $user_id)->first(); + if (!$instructor) { + // Handle case where instructor record doesn't exist + Session::flash('error', get_phrase('Instructor record not found')); + return redirect()->back(); + } + $instructor->status = 1; + $instructor->save(); + + // Send approval notification email + $user->notify(new \App\Notifications\InstructorApprovalNotification($application)); DB::commit(); Session::flash('success', get_phrase('Application approved successfully')); @@ -558,6 +575,7 @@ class UsersController extends Controller return redirect()->back(); } + public function instructor_application_delete($id) { Application::where('id', $id)->delete(); diff --git a/app/Notifications/InstructorApprovalNotification.php b/app/Notifications/InstructorApprovalNotification.php new file mode 100644 index 0000000..437d890 --- /dev/null +++ b/app/Notifications/InstructorApprovalNotification.php @@ -0,0 +1,62 @@ +application = $application; + } + + public function via(object $notifiable): array + { + return ['mail']; + } + + public function toMail(object $notifiable): MailMessage + { + $actionUrl = url('/instructor/dashboard'); + + return (new MailMessage) + ->subject('Instructor Application Approved - GROWNESA') + ->view('vendor.notifications.email', [ + 'actionUrl' => $actionUrl, + 'actionText' => 'Access Instructor Dashboard', + 'extraMessage' => $this->buildEmailContent($notifiable) + ]); + } + + protected function buildEmailContent($notifiable) + { + $content = "Congratulations " . $notifiable->name . "!\n\n"; + $content .= "We are pleased to inform you that your instructor application has been approved.\n\n"; + $content .= "Application ID: " . $this->application->id . "\n\n"; + $content .= "You now have access to:\n"; + $content .= "• Instructor Dashboard\n"; + $content .= "• Course Creation Tools\n"; + $content .= "• Bootcamp Creation Tools\n"; + $content .= "• Blog Creation Tools\n"; + $content .= "• Revenue Tracking and Analytics\n\n"; + $content .= "If you have any questions, please contact our support team.\n\n"; + $content .= "Thank you for joining our instructor community!"; + + return $content; + } + + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} \ No newline at end of file diff --git a/resources/views/vendor/notifications/email.blade.php b/resources/views/vendor/notifications/email.blade.php index fdb569b..f9034ae 100644 --- a/resources/views/vendor/notifications/email.blade.php +++ b/resources/views/vendor/notifications/email.blade.php @@ -66,6 +66,11 @@ font-size: 14px; border-top: 1px solid #dddddd; } + + .email-content { + white-space: pre-line; + margin-bottom: 20px; + } @@ -75,35 +80,43 @@ @endphp
@@ -112,5 +125,4 @@
- \ No newline at end of file