Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions app/Http/Controllers/Api/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Str;
use App\Http\Controllers\Api\PermissionsController;
use App\Http\Requests\Api\PermissionRequest;
use App\Http\Requests\Api\UserRequest;
use Illuminate\Support\Facades\Log;

class MailController extends Controller
Expand Down Expand Up @@ -49,4 +50,66 @@ public function sendEmail(Request $request)

return response()->json(["message" => "Correo enviado a $recipientEmail"]);
}
/*
public function sendAvisos(UserRequest $request){
$correos = $request->input("emailuser");
$details = "hola mundo";
Mail::to("1abelpacheco9@gmail.com")->send(new Mails($details));
return "correo enviado";
}
*/
/*
public function sendAvisos(UserRequest $request)
{
// Obtener los correos del request
$correos = $request->input("emailuser");

// Verificar si $correos es un array
if (!is_array($correos) || empty($correos)) {
return response()->json(["message" => "No se proporcionaron correos validos."], 400);
}

// Detalles del correo
$details = [
'title' => "Aviso importante",
'body' => "Este es un aviso para todos los destinatarios."
];

// Enviar el correo a cada dirección
try {
foreach ($correos as $correo) {
Mail::to($correo)->send(new Mails($details));
}
return response()->json(["message" => "Correos enviados exitosamente."]);
} catch (\Exception $e) {
Log::error('Error al enviar correos: ' . $e->getMessage());
return response()->json(["message" => "Error al enviar los correos."], 500);
}
}
*/
public function sendAvisos(UserRequest $request)
{
// Correos de prueba
$correos = [
"202000212@est.umss.edu",
"1abelpacheco9@gmail.com",
];

// Detalles del correo
$details = [
'title' => "Aviso importante",
'body' => "Este es un aviso para todos los destinatarios."
];

// Enviar el correo a cada dirección
try {
foreach ($correos as $correo) {
Mail::to($correo)->send(new Mails($details));
}
return response()->json(["message" => "Correos enviados exitosamente."]);
} catch (\Exception $e) {
Log::error('Error al enviar correos: ' . $e->getMessage());
return response()->json(["message" => "Error al enviar los correos."], 500);
}
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/Api/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function toArray($request)
'Imagen_Perfil' => $this->user->profileuser,
];
}),
//array de correos
'Imagen_Perfil' => $this->profileuser,
'created_at' => Carbon::parse($this->created_at)->format('d/m/Y - H:i:s'),
'updated_at' => Carbon::parse($this->updated_at)->format('d/m/Y - H:i:s'),
Expand Down
2 changes: 2 additions & 0 deletions app/Mail/Mails.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function build()
{
return $this->subject('Código secreto')
->view('emails.sendEmails')
->with('details', $this->details)
->view('emails.sendAvisos')
->with('details', $this->details);
}
}
11 changes: 11 additions & 0 deletions resources/views/emails/sendAvisos.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Prueba de avisos por correo</title>
</head>
<body>
<h1>{{ $details['title'] }}</h1>
<p>{{ $details['body'] }}</p>
</body>
</html>
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

// Route::get('sendEmail', [MailController::class, 'sendEmail']);
Route::post('sendEmail', [MailController::class, 'sendEmail']);
Route::post('sendAvisos', [MailController::class, 'sendAvisos']);

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return new UserResource($request->user()->load(['roles', 'user']));
Expand Down