PHPackages                             sowailem/flagable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. sowailem/flagable

ActiveLibrary[Database &amp; ORM](/categories/database)

sowailem/flagable
=================

A Laravel package to add flagging functionality to models

1.1.0(6mo ago)18131MITPHPPHP ^8.0CI passing

Since Aug 16Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/sowailem/Flagable)[ Packagist](https://packagist.org/packages/sowailem/flagable)[ RSS](/packages/sowailem-flagable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

Flagable
========

[](#flagable)

A flexible and robust Laravel package that provides comprehensive flagging functionality for Eloquent models. This package allows any model to flag any other model with different flag types such as like, follow, favorite, bookmark, upvote, downvote, and custom types through a sophisticated multi-table architecture.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Database Architecture](#database-architecture)
- [Usage Guide](#usage-guide)
- [API Reference](#api-reference)
- [Advanced Usage](#advanced-usage)
- [Default Flag Types](#default-flag-types)
- [Performance Considerations](#performance-considerations)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Features
--------

[](#features)

- **Flexible Flagging System**: Any model can flag any other model with polymorphic relationships
- **Multiple Flag Types**: Support for like, follow, favorite, bookmark, upvote, downvote, and unlimited custom types
- **Sophisticated Architecture**: Four-table design for optimal performance and flexibility
- **Easy Integration**: Simple traits to add flagging capabilities to your models
- **Facade Support**: Clean API through Laravel facades
- **Database Migrations**: Automatic database structure setup with proper indexes and constraints
- **Default Seeders**: Pre-configured flag types ready to use
- **Laravel Auto-Discovery**: Automatic service provider and facade registration
- **Polymorphic Relationships**: Full support for different model types as flaggers and targets
- **Unique Constraints**: Prevents duplicate flags with database-level constraints
- **Performance Optimized**: Proper indexing and efficient queries

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 9.0, 10.0, 11.0, or 12.0

Installation
------------

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require sowailem/flagable
```

### Step 2: Run Migrations

[](#step-2-run-migrations)

The package will automatically register its service provider and facade through Laravel's auto-discovery feature.

Run the migrations to create the necessary database tables:

```
php artisan migrate
```

### Step 3: Seed Default Flag Types (Optional)

[](#step-3-seed-default-flag-types-optional)

To populate the database with default flag types:

```
php artisan db:seed --class="Sowailem\Flagable\Database\Seeders\FlagTypeSeeder"
```

This will create the following flag types: `like`, `follow`, `favorite`, `bookmark`, `upvote`, `downvote`.

Quick Start
-----------

[](#quick-start)

### 1. Setup Your Models

[](#1-setup-your-models)

Add the appropriate traits to your models:

```
