Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Markable Laravel Package

maize-tech/laravel-markable

Add likes, bookmarks, favorites, reactions and more to Laravel models with a simple “markable” system. Includes install command, configurable user model and table prefix, and optional publishable migrations per mark type for quick setup.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modular Design: The package follows a clean, modular architecture with separate migrations for each mark type (e.g., like, bookmark, reaction), aligning well with Laravel’s Eloquent conventions. This reduces coupling and allows for granular scaling.
  • Trait-Based Integration: The Markable trait enables seamless integration into existing models without requiring inheritance, preserving flexibility in model design.
  • Type Safety: Support for BackedEnum (introduced in v3.0) enhances type safety, reducing runtime errors and improving IDE support.
  • Configurability: Centralized configuration (e.g., user_model, table_prefix, allowed_values) allows for easy customization without modifying core logic.

Integration Feasibility

  • Laravel Compatibility: Officially supports Laravel 11/12 (as of v2.3.0/v3.0), with backward compatibility for older versions. The package leverages Eloquent’s polymorphic relationships and JSON fields, which are well-supported in modern Laravel.
  • Database Schema: Uses dedicated tables per mark type (e.g., markable_likes, markable_reactions), which simplifies queries but requires careful migration planning to avoid schema conflicts.
  • Customization Points: Extensible via:
    • Custom mark models (extending Maize\Markable\Mark).
    • Dynamic relation names (markableRelationName, markRelationName).
    • Metadata support (JSON field for arbitrary data).
  • Performance: Separate tables for marks optimize query performance for common operations (e.g., count, has), but may increase write overhead for high-frequency actions.

Technical Risk

  • Migration Complexity: Publishing and running migrations for each mark type (bookmark, like, etc.) requires discipline to avoid partial deployments. The package lacks a built-in composite migration tool.
  • Schema Evolution: Future changes to mark tables (e.g., adding columns) may require downtime or complex migration strategies, especially in production.
  • Enum Support: While BackedEnum integration is elegant, it introduces a dependency on PHP 8.1+ and may require additional validation logic in older environments.
  • Concurrency: High-frequency mark operations (e.g., likes on a viral post) could lead to race conditions if not handled at the application level (e.g., optimistic locking).
  • Testing: The package’s test suite is CI-gated but lacks end-to-end tests for edge cases (e.g., concurrent writes, custom mark validation).

Key Questions

  1. Mark Type Selection:
    • How many mark types (e.g., like, bookmark, reaction) will be used? More types increase migration complexity.
    • Are custom mark models needed, or will the built-in types suffice?
  2. Performance Requirements:
    • What are the expected read/write volumes for marks? For example, will Reaction::count() be called frequently on high-traffic models?
    • Are there plans to cache mark counts or user lists (e.g., Redis)?
  3. Metadata Needs:
    • Will custom metadata be stored for marks? If so, how large/complex will the JSON payloads be?
  4. Enum Adoption:
    • Will BackedEnum be used for mark values? If yes, is PHP 8.1+ a hard requirement?
  5. Rollback Strategy:
    • How will mark tables be handled during rollbacks or schema changes (e.g., adding a value column to markable_reactions)?
  6. Monitoring:
    • Are there plans to track mark-related metrics (e.g., latency, failure rates)?
  7. Legacy Support:
    • If using Laravel <11, are there plans to upgrade, or will the package’s older versions be maintained?

Integration Approach

Stack Fit

  • Laravel Ecosystem: The package is a first-class citizen in Laravel, leveraging Eloquent, migrations, and service providers. It integrates smoothly with:
    • Authentication: Uses Laravel’s built-in auth()->user() for mark ownership.
    • APIs: Works seamlessly with Laravel Sanctum/Passport for authenticated mark operations.
    • Frontend: Supports real-time updates via Laravel Echo/Pusher for live mark toggles.
    • Testing: Compatible with Laravel’s testing tools (e.g., assertDatabaseHas for mark assertions).
  • Database: Optimized for PostgreSQL/MySQL, with support for JSON fields (metadata) and polymorphic relationships.
  • Caching: Can be extended with Laravel Cache for mark counts or user lists (e.g., Reaction::count() cached per model).

Migration Path

  1. Assessment Phase:
    • Audit existing models to identify candidates for markable traits (e.g., Post, Course).
    • Decide on mark types (e.g., like, bookmark) and whether custom marks are needed.
  2. Setup:
    • Install the package: composer require maize-tech/laravel-markable.
    • Publish the config: php artisan markable:install.
    • Configure user_model and table_prefix in config/markable.php.
  3. Migration Strategy:
    • Option A (Big Bang): Publish all required migrations (bookmark, like, etc.) and run php artisan migrate in one deployment. Risk: Downtime if migrations fail.
    • Option B (Phased): Publish and migrate mark tables incrementally, starting with the most critical (e.g., like). Risk: Inconsistent mark types across models.
    • Option C (Zero-Downtime): Use Laravel’s schema modifications with down() methods to add tables without downtime (requires careful planning).
  4. Model Integration:
    • Add the Markable trait and define $marks in target models (e.g., Post, Course).
    • Example:
      use Maize\Markable\Markable;
      use Maize\Markable\Models\Like;
      
      class Post extends Model {
          use Markable;
          protected static $marks = [Like::class];
      }
      
  5. Customization:
    • Extend Maize\Markable\Mark for custom marks (e.g., Bookmark).
    • Define allowed_values in config for marks with restricted values (e.g., reactions).
    • Implement BackedEnum for type-safe mark values if using PHP 8.1+.
  6. Testing:
    • Write unit tests for mark operations (e.g., Like::add(), Reaction::count()).
    • Test edge cases: duplicate marks, invalid values, concurrent writes.
    • Use Laravel’s assertDatabaseHas to verify mark persistence.

Compatibility

  • Laravel Versions: Officially supports 11/12; test thoroughly if using 10 or older.
  • PHP Versions: Requires PHP 8.1+ for BackedEnum support (optional feature).
  • Database: Tested on PostgreSQL/MySQL; SQLite may require adjustments for JSON field support.
  • Third-Party Packages:
    • Laravel Scout: Mark counts can be indexed for search (e.g., "posts with >100 likes").
    • Laravel Nova: Custom tool integration for managing marks via the admin panel.
    • Laravel Horizon: Queue mark operations (e.g., Like::add()) for async processing.

Sequencing

  1. Pre-Deployment:
    • Back up the database.
    • Test migrations in a staging environment.
    • Document the rollback plan for mark tables.
  2. Deployment:
    • Run migrations during a low-traffic window.
    • Deploy model changes (adding Markable trait) in a separate step to avoid coupling.
  3. Post-Deployment:
    • Monitor mark-related queries for performance issues.
    • Update frontend to reflect new mark APIs (e.g., /posts/{id}/like).
    • Implement caching for frequently accessed mark data (e.g., Reaction::count()).

Operational Impact

Maintenance

  • Configuration Drift: Centralized config (config/markable.php) reduces drift but requires discipline to update it consistently across environments.
  • Schema Changes: Adding new mark types or modifying existing ones (e.g., adding a value column) requires:
    • New migrations.
    • Potential downtime for complex changes.
    • Updates to custom mark models if schema changes affect them.
  • Dependency Updates: Monitor for breaking changes in Laravel or PHP versions (e.g., Laravel 13 may require package updates).
  • Custom Logic: Custom mark models or metadata fields may introduce maintenance overhead if business logic evolves.

Support

  • Common Issues:
    • Duplicate Marks: Ensure idempotent operations (e.g., Like::toggle()) handle duplicates gracefully.
    • Permission Errors: Validate that user_id in mark tables matches authenticated users.
    • Performance Bottlenecks: Optimize queries for count() or has() operations on large datasets.
  • Debugging Tools:
    • Use Laravel Debugbar to inspect mark queries.
    • Log mark operations for auditing (e.g., Like::add() events).
  • Documentation:
    • Maintain a runbook for:
      • Resetting mark tables (e.g., `TRUNCATE mark
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai