This Laravel application is a multi-user platform for creating, managing, and interacting with posts. It implements features such as likes, comments, categories, user roles, and more.
- User authentication using Laravel Breeze.
- Role-based access control:
- Admin: Full control over posts, users, and categories.
- Author: Can create and manage their own posts.
- General User: Can view posts, like posts, and leave comments.
- Authors and admins can:
- Create posts with rich content (text/images).
- Assign categories and other authors to posts.
- Edit or delete posts as required.
- Rich text editing support with image upload (via base64 or file storage).
- Tracks likes, views, and comments per post.
- Posts can be associated with one or more categories.
- Displays posts by category with filtering.
- Accessible via
/posts/category/{id}route.
- Users can like/unlike posts.
- Like count dynamically updates and tracks liked/unliked status per user.
- Authenticated users can comment on posts.
- Nested relationship implemented to display comments with user details.
- Role-based access middleware:
- AdminMiddleware restricts access to admin-only routes.
- PostMiddleware restricts post actions for authors and admins.
- Protects routes and ensures integrity of user operations.
- Displays all posts with:
- Posts and their associations: categories, author(s), likes, views.
- Categories filtering.
- Admin-specific features for managing posts and users.
Ensures that only users with the role admin can access admin-specific routes. If unauthorized, it redirects the user back to the dashboard with an error message.
Restricts post-related actions such as creation or editing to users with admin or author roles. If unauthorized, it returns a 403 Forbidden response.
Here is an overview of the routes and their responsibilities:
/
Redirects authenticated users to the dashboard, or displays the welcome page for guests.
-
Dashboard
/dashboard
Displays all posts, categories, and filters (requires login). -
Profile Management
/profile: User profile edit page./profile [PATCH]: Update user profile./profile [DELETE]: Delete user account.
- Post Management
GET /posts/create: Show create post form.POST /create: Store new post.
-
User Management
GET /admin/users: List all users for admin management.PUT /admin/users/{id}: Update a user.DELETE /admin/users/{id}: Delete a user.
-
Post Administration
GET /post/{id}/edit: Edit posts.PUT /post/{id}: Update posts.DELETE /post/{id}: Delete posts.
-
View Post
GET /post/{id}: Show a single post. -
Post Likes
GET /like/{id}: Like or unlike a post. -
Post Comments
POST /comment: Add a comment to a post. -
Posts by Category
GET /posts/category/{id}: Show all posts in a specific category.
- Users Table
Stores basic user information, including roles (admin/author/user). - Categories Table
Manages categories for classifying posts. - Posts Table
Stores metadata and content for posts. - Likes Table
Tracks user likes for posts. - Comments Table
Stores user comments on posts. - Category_Post Table
Many-to-many relationship between posts and categories. - Post_User Table
Many-to-many relationship for authors collaborating on posts. - Views Table
Tracks and counts post views.
- A Post belongs to a User (author).
- Posts have:
- Many comments.
- Many categories.
- Many authors (collaboration).
- Many likes (Like model).
- Many views.
- Extended from
Authenticatable. - Relationships:
- posts(): Has many posts authored by the user.
- Stores post information, with relationships:
- user(): Belongs to a user (author).
- categories(): Many-to-many relationship with categories.
- authors(): Many-to-many relationship with collaborating authors.
- likes(): Has many likes associated with the post.
- comments(): Has many comments associated with the post.
- views(): Has many views associated with the post.
- Tracks if a post is liked by the authenticated user (
isLikedByUser).
- Categories associated with posts.
- Provides methods for retrieving posts under a specific category.
- Tracks likes for posts, associated with both user and post IDs.
- Dashboard: Displays all posts and allows interaction (like, comment, and view).
- Create Post: Form to create new posts with categories and collaborators.
- Edit Post: Admins can edit post content and metadata.
- View Post: Displays single post details, comments, and like status.
- Using the
LikeController, users can toggle like/unlike states for posts. - Stored efficiently in the
likestable with boolean status.
- Saved automatically upon retrieving a post if it is accessed through the
showmethod.
- Comments are stored with user and post associations, supporting nested views where applicable.
- Posts include associated data:
- Categories.
- Likes and count of likes.
- Authors.
- Comments and associated users.
- Content is cleaned to remove potential harmful scripts and HTML.
- Admins can manage both users (edit, delete) and posts (edit, delete).
- Authentication: Handled by Laravel Breeze.
- Rich Text Content: Managed with integrated file handling for images and post content.
- Storage System: Used for base64 and regular image uploads.
- Category Management: Integrated with filtering and multi-category posts.