feat: funcionalidad de red social (feed, amigos, búsqueda)

- Migraciones: posts, post_likes, post_comments
- Modelos Post, PostLike, PostComment con relaciones
- User: métodos friendshipWith, isFriendWith, friendIds, posts
- PostController: feed, crear publicación con imagen, like toggle, comentarios, eliminar
- FriendshipController: listar solicitudes, enviar, aceptar, rechazar, toggle AJAX
- SocialProfileController: perfil público con publicaciones y estado de amistad
- UserSearchController: búsqueda AJAX por nombre con estado de amistad
- FriendRequestNotification: notificación al recibir solicitud
- Vistas: feed/index, feed/_post, friendships/index, social/profile
- Header: barra de búsqueda con autocomplete AJAX (agregar amigo / mensaje)
- Menú lateral: Comunidad, Amigos, Mensajes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-28 17:09:04 -06:00
parent 0f7de9b4d8
commit 97c04fbfb4
22 changed files with 1005 additions and 308 deletions
+39
View File
@@ -131,6 +131,45 @@ class User extends Authenticatable
return $this->belongsToMany(Alumno::class);
}
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
public function sentFriendRequests(): HasMany
{
return $this->hasMany(Friendship::class, 'sender_id');
}
public function receivedFriendRequests(): HasMany
{
return $this->hasMany(Friendship::class, 'receiver_id');
}
public function friendshipWith(User $user): ?Friendship
{
return Friendship::where(function ($q) use ($user) {
$q->where('sender_id', $this->id)->where('receiver_id', $user->id);
})
->orWhere(function ($q) use ($user) {
$q->where('sender_id', $user->id)->where('receiver_id', $this->id);
})
->first();
}
public function isFriendWith(User $user): bool
{
$friendship = $this->friendshipWith($user);
return $friendship?->status === 'accepted';
}
public function friendIds(): array
{
$sent = Friendship::where('sender_id', $this->id)->where('status', 'accepted')->pluck('receiver_id');
$received = Friendship::where('receiver_id', $this->id)->where('status', 'accepted')->pluck('sender_id');
return $sent->merge($received)->unique()->values()->all();
}
protected static function booted()
{
static::creating(function ($user) {