This repository contains a Laravel 11 application with a feature for managing flashcards through an interactive console command.
This repo has the following branches:
- main: Contains the base Laravel 11 code.
- clean-up: Derived from
main
, this branch removes unnecessary files/containers. - interactive-command: Derived from
clean-up
, Contains the code related to the flashcards interactive command.
- main -> clean-up -> interactive-command
A Pull Request has been created from interactive-command
to clean-up
for easy code review.
The primary feature of this repository is a Laravel console command that manages flashcards. Below are the key files related to this feature:
app/Console/Commands/FlashcardInteractive.php
app/Services/FlashcardService.php
app/Services/FlashcardPracticeService.php
app/Services/MenuService.php
app/Models/Flashcard.php
app/Models/FlashcardPractice.php
app/Enums/MenuItem.php
app/Enums/FlashcardPracticeStatus.php
tests/Feature/FlashcardCommandTest.php
tests/Unit/FlashcardPracticeTest.php
tests/Unit/FlashcardTest.php
tests/Unit/MenuTest.php
- Database migration files are located in
database/migrations
.
Two tables are created for the flashcard functionality:
flashcards
[id, question, answer]flashcard_practices
[id, flashcard_id, user_id, answer, status]
Note: Although we currently don't have a user
entity in the system, the user_id
is included in the flashcard_practices
table to allow future user integration. For now, the user_id
is passed as a command argument.
- Docker
- WSL2 (for Windows users)
-
Clone the repository:
git clone [email protected]:tayyabhussainit/flashcard.git cd flashcard
-
Checkout the
interactive-command
branch:git checkout interactive-command
-
Copy the environment file:
cp .env.example .env
-
Install dependencies:
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/var/www/html" -w /var/www/html laravelsail/php83-composer:latest composer install --ignore-platform-reqs
Reference: https://laravel.com/docs/11.x/sail#installing-composer-dependencies-for-existing-projects
-
Start the project using WSL (required for setup on windows):
wsl -d ubuntu
-
Go to the project directory (inside WSL, required for setup on windows).
-
Start the Docker containers:
./vendor/bin/sail up -d
-
Generate the application key:
./vendor/bin/sail artisan key:generate
-
Run migrations:
./vendor/bin/sail artisan migrate
To run the flashcards interactive command, use the following:
./vendor/bin/sail artisan flashcard:interactive {user_id}
example:
./vendor/bin/sail artisan flashcard:interactive 1
To run the test cases, "testing" database must be created:
./vendor/bin/sail mysql
mysql> CREATE DATABASE testing;
mysql> exit
./vendor/bin/sail artisan test
To ensure code quality, PHP Code Sniffer was used to check the code for any violations of coding standards.
-
Access the Docker container:
./vendor/bin/sail bash
-
Run PHP Code Sniffer on specific files or directories:
-
To check the
FlashcardInteractive
command file:./vendor/bin/phpcs -v app/Console/Commands/FlashcardInteractive.php
-
To check the
Services
directory:./vendor/bin/phpcs -v app/Services/
-
To check the
Models
directory:./vendor/bin/phpcs -v app/Models/
-
To check the
Enums
directory:./vendor/bin/phpcs -v app/Enums/
-
Screenshots of the commands, tests and schema exists in screenshots folder at root