A Poll Management System built with Laravel 11, utilizing Breeze for authentication, Alpine.js for frontend interactivity, and Reverb WebSocket for real-time communication. This application allows admins to create polls, display them to users, and manage voting efficiently.
Before you begin, ensure you have met the following requirements:
- PHP: Version 8.2 or higher
- Node.js: Version 14 or higher
- SQLite Driver: Ensure the SQLite driver is enabled in your PHP installation.
- Admin Poll Creation: A simple interface for creating polls with one question and multiple options.
- Poll Display: A public page for displaying poll questions and options with a shareable link.
- Vote Submission: An endpoint for authenticated (or guest) users to submit votes.
- One Vote per User/IP: Mechanism to ensure each user can only vote once.
- Real-Time Updates: Broadcasts updated vote counts using Laravel's event broadcasting and WebSockets.
- Client-Side Integration: A frontend that listens for broadcast events and updates poll results in real-time.
- Laravel 11: The backend framework for building the application.
- Breeze: For user authentication and simple UI scaffolding.
- Alpine.js: For enhancing frontend interactivity.
- Reverb WebSocket: For real-time communication and updates.
- SQLite: Database for storing poll and vote data.
-
Clone the repository:
git clone https://github.com/abhihyder/poll-man.git cd poll-man
-
Install dependencies:
composer install npm install
-
Build the frontend:
After installing the npm dependencies, run the following command to build the frontend assets:
npm run build
-
Set up your environment variables:
Copy the
.env.example
file to.env
and configure your database and other settings:cp .env.example .env
All the required values for environment variables are already defined in the
.env.example
file, making it easy for you to get started with testing. -
Generate the application key:
php artisan key:generate
-
Run migrations:
php artisan migrate
-
Start the local development server:
php artisan serve
-
Run WebSocket server:
php artisan reverb:start
-
Run Queue:
php artisan queue:work
This project includes automated tests to ensure the functionality of the polling system. The following tests are implemented:
The PollVoteTest
includes two main test cases:
-
User Can Vote in Poll:
- This test checks that a user can successfully vote in an active poll. It verifies that the vote is recorded in the database.
-
User Cannot Vote More Than Once:
- This test ensures that a user cannot vote more than once for the same poll. If a user tries to vote again, the response will return an error indicating that they have already voted.
To run the tests, use the following command:
php artisan test --filter PollVoteTest
After successfully running the tests, you can populate the database with an admin user and a sample poll using the following commands:
php artisan db:seed
-
Login Instructions: Use the following credentials to log in as the admin user:
- Email:
admin@example.com
- Password:
password
- Email:
-
Public Poll Page: Visit the public page (e.g.,
/
) to see the available polls. -
Voting: Users can submit their votes through the public poll page.
- GET /dashboard: View all polls as an admin.
- GET /: Display all public polls.
- POST /poll: Create a new poll.
- GET /poll/{uid}: Display single poll.
- POST /poll/vote: Submit a vote for a poll option.
This application utilizes Laravel's event broadcasting capabilities to provide real-time updates. When a vote is cast, the updated vote count is broadcasted to all connected clients via Reverb WebSocket.
- The frontend listens for broadcast events to update the poll results in real-time using Laravel Echo and Pusher.js for WebSocket communication.
- Alpine.js is utilized to manage dynamic updates on the poll results page.
If you want to set up the project with Docker, you can use the following Docker Repository.