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
- @if ($condition) - {{ get_phrase('Please click the button below to verify your email address.') }} - @elseif($current_route == 'password.email') - {{ get_phrase('Please click the button below to reset your password.') }} - @endif -
+ @if ($current_route == 'register' || $current_route == 'verification.send' || $current_route == 'admin.admins.store' || $current_route == 'admin.instructor.store' || $current_route == 'admin.student.store' || (isset($_GET['type']) && $_GET['type'] == 'registration')) +{{ get_phrase('Please click the button below to verify your email address.') }}
+ @elseif($current_route == 'password.email') +{{ get_phrase('Please click the button below to reset your password.') }}
+ @else +{{ $extraMessage }}
@endif +{{ get_phrase('If you did not request this, you can ignore this email.') }}
{{ get_phrase('Thank you!') }}