Download the PHP package sowailem/flagable without Composer

On this page you can find all versions of the php package sowailem/flagable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package 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

Features

Requirements

Installation

Step 1: Install via Composer

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:

Step 3: Seed Default Flag Types (Optional)

To populate the database with default flag types:

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

Quick Start

1. Setup Your Models

Add the appropriate traits to your models:

2. Basic Usage

Database Architecture

The package uses a sophisticated four-table architecture for maximum flexibility and performance:

Tables Structure

1. flag_types Table

Stores available flag types (like, follow, etc.)

2. flag_targets Table

Stores model class names that can be flagged

3. flag_links Table

Links flag types to target model types (pivot table)

4. flags Table

Stores individual flag records

Relationships Diagram

Usage Guide

Using Traits

CanFlag Trait

Add this trait to models that can flag other models:

Available Methods:

Flagable Trait

Add this trait to models that can be flagged by other models:

Available Methods:

Using the Facade

API Reference

CanFlag Trait Methods

flag(Model $target, string $type): Flag

Creates a flag record for the target model.

Parameters:

Returns: Flag model instance

Example:

unflag(Model $target, string $type): bool

Removes a flag record for the target model.

Parameters:

Returns: bool - True if flag was removed, false otherwise

Example:

hasFlagged(Model $target, ?string $type = null): bool

Checks if this model has flagged the target model.

Parameters:

Returns: bool

Example:

flags(): MorphMany

Gets all flags created by this model.

Returns: MorphMany relationship

Example:

Flagable Trait Methods

isFlaggedBy(Model $flagger, ?string $type = null): bool

Checks if this model is flagged by the specified flagger.

Parameters:

Returns: bool

Example:

flagCount(?string $type = null): int

Gets the count of flags for this model.

Parameters:

Returns: int

Example:

flaggers(string $type, string $flaggerModel): Collection

Gets all models that have flagged this model with the specified type.

Parameters:

Returns: Collection

Example:

flags(): HasManyThrough

Gets all flag records for this model.

Returns: HasManyThrough relationship

Example:

Facade Methods

Flag::addFlagType(string $name): FlagType

Creates a new flag type.

Parameters:

Returns: FlagType model instance

Flag::removeFlagType(string $name): bool

Removes a flag type.

Parameters:

Returns: bool

Flag::flag(Model $flagger, Model $target, string $type): Flag

Creates a flag record.

Parameters:

Returns: Flag model instance

Flag::unflag(Model $flagger, Model $target, string $type): bool

Removes a flag record.

Parameters:

Returns: bool

Flag::isFlaggedBy(Model $target, Model $flagger, ?string $type = null): bool

Checks if target is flagged by flagger.

Flag::getFlagCount(Model $target, ?string $type = null): int

Gets flag count for target.

Flag::getFlaggers(Model $target, string $type, string $flaggerModel): Collection

Gets all flaggers for target.

Advanced Usage

Custom Flag Types

You can create custom flag types dynamically:

Bulk Operations

Complex Queries

Model Relationships

Default Flag Types

The package comes with six predefined flag types that are created when you run the seeder:

Using Default Types

Performance Considerations

Database Indexes

The package automatically creates the following indexes for optimal performance:

Query Optimization

Caching Strategies

Troubleshooting

Common Issues

1. "Class not found" errors

Make sure you've run composer dump-autoload after installation.

2. Migration errors

Ensure you're running the migrations in the correct order. The package migrations are numbered to run in sequence.

3. Duplicate flag errors

The package prevents duplicate flags at the database level. If you're getting constraint violations, check if the flag already exists before creating it:

4. Performance issues with large datasets

Use eager loading and database-level aggregations:

5. Memory issues with large collections

Use chunking for bulk operations:

Debug Mode

Enable query logging to debug performance issues:

Validation

Always validate flag types before using them:

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository and create your feature branch
  2. Write tests for any new functionality
  3. Follow PSR-12 coding standards
  4. Update documentation for any API changes
  5. Submit a pull request with a clear description

Development Setup

Reporting Issues

When reporting issues, please include:

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Security Considerations

Credits

License

The MIT License (MIT). Please see License File for more information.


Flagable provides a flexible and robust way to implement flagging functionality in Laravel applications. The sophisticated four-table architecture allows for multiple flag types (like, follow, favorite, etc.) and supports any model flagging any other model with optimal performance and data integrity.


All versions of flagable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^9.0|^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sowailem/flagable contains the following files

Loading the files please wait ...