Controladores
El proyecto cuenta con controladores para gestionar las diferentes funcionalidades del sistema.
1. DashboardController
Ubicación: app/Http/Controllers/Tools/DashboardController.php
Controlador para el panel de administración con estadísticas.
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
index |
GET | /dashboard |
Panel con estadísticas | auth verified |
Código del método index
public function index(Request $request): View
{
// Estadísticas de usuarios
$users = [
'total' => User::count(),
'admin' => User::whereHas('role', fn($q) => $q->where('name', 'admin'))->count(),
'speaker' => User::whereHas('role', fn($q) => $q->where('name', 'ponente'))->count(),
'assistant' => User::whereHas('role', fn($q) => $q->where('name', 'asistente'))->count(),
];
// Estadísticas de presentaciones
$presentations = [
'total' => Presentation::count(),
'published' => Presentation::where('published', true)->count(),
'no_published' => Presentation::where('published', false)->count(),
];
// Estadísticas de pósters
$posters = [
'total' => Poster::count(),
'published' => Poster::where('published', true)->count(),
'no_published' => Poster::where('published', false)->count(),
];
// Estadísticas de patrocinadores
$sponsors = [
'total' => Sponsor::count(),
'oro' => Sponsor::whereHas('type_sponsor', fn($q) => $q->where('name', 'oro'))->count(),
'plata' => Sponsor::whereHas('type_sponsor', fn($q) => $q->where('name', 'plata'))->count(),
'bronce' => Sponsor::whereHas('type_sponsor', fn($q) => $q->where('name', 'bronce'))->count(),
];
return view('dashboard', compact('users', 'presentations', 'posters', 'sponsors'));
}
2. PosterController
Ubicación: app/Http/Controllers/PosterController.php
Controlador para gestionar los pósters del congreso.
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
index | GET | /dashboard/posters | Lista pósters | auth, verified, admin-speaker |
create | GET | /dashboard/posters/create/{user} | Formulario creación | auth, verified, admin-speaker, owner-poster-create |
store | POST | /dashboard/posters/store/{user} | Guardar póster | auth, verified, admin-speaker |
edit | GET | /dashboard/posters/{poster}/edit | Formulario edición | auth, verified, admin-speaker, owner-poster-edit |
update | PUT | /dashboard/posters/{poster} | Actualizar póster | auth, verified, admin-speaker |
destroy | DELETE | /dashboard/posters/{poster} | Eliminar póster | auth, verified, admin-speaker |
publish | PUT | /dashboard/posters/publish/{poster} | Publicar/despublicar | auth, verified, admin-speaker |
postersPublic | GET | /posters/public | Lista pública | - |
postersSearch | GET | /posters/public/search | Buscar pósters | - |
Código del método store
public function store(CreatePosterRequest $request, User $user): RedirectResponse
{
$data = $request->validated();
// Obtener categoría o usar la predeterminada
$categoryId = $data['category_id'] ?? Category::first()->id;
// Obtener tipo de presentación (poster)
$typePresentation = TypePresentation::where('name', 'poster')->first();
// Guardar archivo
$urlFile = $this->saveFile($request->file('url_file'));
// Crear póster
$poster = Poster::create([
'title' => $data['title'],
'summary' => $data['summary'],
'url_file' => $urlFile,
'type_presentation_id' => $typePresentation->id,
'user_id' => $user->id,
'category_id' => $categoryId,
'published' => false,
]);
return redirect()->route('dashboard.posters')
->with('success', 'Póster creado correctamente');
}
Código del método update
public function update(UpdatePosterRequest $request, Poster $poster): RedirectResponse
{
$data = $request->validated();
$poster->update($data);
// Si hay nuevo archivo, actualizar
if ($request->hasFile('url_file')) {
$this->deletePreviusFile($poster->url_file);
$urlFile = $this->saveFile($request->file('url_file'));
$poster->update(['url_file' => $urlFile]);
}
return redirect()->route('dashboard.posters')
->with('success', 'Póster actualizado correctamente');
}
Métodos privados
private function getFileName(string $title): string
{
return Str::slug($title) . '-' . time() . '.pdf';
}
private function saveFile(UploadedFile $file): string
{
$fileName = $this->getFileName($file->getClientOriginalName());
$file->storeAs('posters', $fileName, 'public');
return 'posters/' . $fileName;
}
private function deletePreviusFile(string $url): void
{
Storage::disk('public')->delete($url);
}
3. PresentationController
Ubicación: app/Http/Controllers/PresentationController.php
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
index | GET | /dashboard/presentations | Lista presentaciones | auth, verified, admin-speaker |
create | GET | /dashboard/presentations/create/{user} | Formulario creación | auth, verified, admin-speaker, owner-presentation-create |
store | POST | /dashboard/presentations/store/{user} | Guardar presentación | auth, verified, admin-speaker |
edit | GET | /dashboard/presentations/{presentation}/edit | Formulario edición | auth, verified, admin-speaker, owner-presentation-edit |
update | PUT | /dashboard/presentations/{presentation} | Actualizar presentación | auth, verified, admin-speaker |
destroy | DELETE | /dashboard/presentations/{presentation} | Eliminar presentación | auth, verified, admin-speaker |
publish | PUT | /dashboard/presentations/publish/{presentation} | Publicar/despublicar | auth, verified, admin-speaker |
Código del método store
public function store(CreatePresentationRequest $request, User $user): RedirectResponse
{
$data = $request->validated();
// Obtener categoría o usar la predeterminada
$categoryId = $data['category_id'] ?? Category::first()->id;
// Obtener tipo de presentación (oral)
$typePresentation = TypePresentation::where('name', 'oral')->first();
// Obtener tipo de archivo
$typeFile = $this->typePresentation($request->file('url_file')->getClientOriginalExtension());
// Guardar archivo
$urlFile = $this->saveFile($request->file('url_file'));
// Crear presentación
$presentation = Presentation::create([
'title' => $data['title'],
'summary' => $data['summary'],
'url_file' => $urlFile,
'type_file' => $typeFile,
'type_presentation_id' => $typePresentation->id,
'user_id' => $user->id,
'category_id' => $categoryId,
'published' => false,
]);
return redirect()->route('dashboard.presentations')
->with('success', 'Presentación creada correctamente');
}
Método typePresentation
private function typePresentation(string $extension): string
{
$extension = strtolower($extension);
return match($extension) {
'pdf' => 'PDF',
'ppt', 'pptx' => 'POWERPOINT',
'key' => 'KEY',
'odp' => 'ODP',
default => 'OTRO',
};
}
4. CategoryController
Ubicación: app/Http/Controllers/CategoryController.php
Controlador para gestionar las categorías del congreso.
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
index | GET | /dashboard/categories | Lista categorías | auth, verified, admin |
create | GET | /dashboard/categories/create | Formulario creación | auth, verified, admin |
store | POST | /dashboard/categories/store | Guardar categoría | auth, verified, admin |
edit | GET | /dashboard/categories/{category}/edit | Formulario edición | auth, verified, admin |
update | PUT | /dashboard/categories/{category} | Actualizar categoría | auth, verified, admin |
destroy | DELETE | /dashboard/categories/{category} | Eliminar categoría | auth, verified, admin |
Código del método destroy
public function destroy(Category $category): RedirectResponse
{
// Verificar si es la categoría general
if ($category->id === 1) {
return redirect()->route('dashboard.categories')
->with('error', 'No se puede eliminar la categoría General');
}
$category->delete();
return redirect()->route('dashboard.categories')
->with('success', 'Categoría eliminada correctamente');
}
5. SponsorController
Ubicación: app/Http/Controllers/SponsorController.php
Controlador para gestionar los patrocinadores del congreso.
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
index | GET | /dashboard/sponsors | Lista patrocinadores | auth, verified, admin |
create | GET | /dashboard/sponsors/create | Formulario creación | auth, verified, admin |
store | POST | /dashboard/sponsors/store | Guardar patrocinador | auth, verified, admin |
edit | GET | /dashboard/sponsors/{sponsor}/edit | Formulario edición | auth, verified, admin |
update | PUT | /dashboard/sponsors/{sponsor} | Actualizar patrocinador | auth, verified, admin |
destroy | DELETE | /dashboard/sponsors/{sponsor} | Eliminar patrocinador | auth, verified, admin |
6. UsersController
Ubicación: app/Http/Controllers/UsersController.php
Controlador para gestionar los usuarios del sistema.
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
index | GET | /dashboard/users | Lista usuarios | auth, verified, admin |
create | GET | /dashboard/users/create | Formulario creación | auth, verified, admin |
store | POST | /dashboard/users/store | Guardar usuario | auth, verified, admin |
edit | GET | /dashboard/users/{user}/edit | Formulario edición | auth, verified, admin |
update | PUT | /dashboard/users/{user} | Actualizar usuario | auth, verified, admin |
destroy | DELETE | /dashboard/users/{user} | Eliminar usuario | auth, verified, admin |
Código del método store
public function store(CreateUserRequest $request): RedirectResponse
{
$data = $request->validated();
// Crear usuario con contraseña encriptada
User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role_id' => $data['role_id'],
]);
return redirect()->route('dashboard.users')
->with('success', 'Usuario creado correctamente');
}
7. ProfileController
Ubicación: app/Http/Controllers/ProfileController.php
Controlador para gestionar el perfil del usuario autenticado.
Métodos
| Método | HTTP | Ruta | Descripción | Middleware |
|---|---|---|---|---|
edit | GET | /profile | Formulario edición | auth |
update | PATCH | /profile | Actualizar perfil | auth |
destroy | DELETE | /profile | Eliminar cuenta | auth |
Código del método update
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
$request->user()->save();
return redirect()->route('profile.edit')
->with('status', 'Perfil actualizado correctamente');
}