PHPackages                             modularavel/favoritable - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. modularavel/favoritable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

modularavel/favoritable
=======================

A Laravel Livewire package to add favorites functionality to your application

v1.0.0(7mo ago)00MITPHPPHP &gt;=8.1

Since Oct 9Pushed 7mo agoCompare

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

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

modularavel/favoritable
=======================

[](#modularavelfavoritable)

A Laravel Livewire package that adds favorites functionality to your Laravel 11+ application. Allow users to favorite any model in your application with a beautiful, customizable UI.

Features
--------

[](#features)

- Add favorites to any Eloquent model
- Beautiful Livewire components with multiple variants
- Favorite button with counter
- Favorites list page
- Tailwind CSS styling included
- Full test coverage with Pest
- Easy to customize
- Real-time updates

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

[](#requirements)

- PHP 8.2+
- Laravel 11.0+ or Laravel 12.0+
- Livewire 3.0+
- Tailwind CSS

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

[](#installation)

Install the package via Composer:

```
composer require modularavel/favoritable
```

Publish the migrations:

```
php artisan vendor:publish --tag="modularavel:favoritable-migrations"
```

Run the migrations:

```
php artisan migrate
```

Optionally, publish the config file:

```
php artisan vendor:publish --tag="modularavel:favoritable-config"
```

Optionally, publish the views for customization:

```
php artisan vendor:publish --tag="modularavel:favoritable-views"
```

Setup
-----

[](#setup)

### 1. Add the Trait to Your Model

[](#1-add-the-trait-to-your-model)

Add the `Favoritable` trait to any model you want users to be able to favorite:

```
use Modularavel\Favoritable\Traits\HasModularavelFavoritable;

class Post extends Model
{
    use HasModularavelFavoritable;
}
```

### 2. Import CSS Styles

[](#2-import-css-styles)

Add the package CSS to your main CSS file or import it in your layout:

```
@import '../../vendor/modularavel/favoritable/resources/css/favoritable.css';
```

Or include it directly in your Tailwind config:

```
module.exports = {
  content: [
    './vendor/modularavel/favoritable/resources/**/*.blade.php',
  ],
}
```

Usage
-----

[](#usage)

### Favorite Button Component

[](#favorite-button-component)

The simplest way to add a favorite button:

```

```

#### Button Variants

[](#button-variants)

Choose from multiple button styles:

```
{{-- Default variant --}}

{{-- Outline variant --}}

{{-- Solid variant --}}

{{-- Icon only variant --}}

```

#### Button Sizes

[](#button-sizes)

Choose from three sizes:

```
{{-- Small --}}

{{-- Medium (default) --}}

{{-- Large --}}

```

#### Hide Counter

[](#hide-counter)

You can hide the favorites counter:

```

```

### Favorites List Component

[](#favorites-list-component)

Display a paginated list of user's favorites:

```

```

#### Filter by Type

[](#filter-by-type)

Show only favorites of a specific type:

```

```

#### Custom Pagination

[](#custom-pagination)

```

```

### Model Methods

[](#model-methods)

The `Favoritable` trait adds several helpful methods to your models:

```
// Check if favorited by a user
$post->isFavoritedBy($user);

// Toggle favorite
$post->toggleFavorite($user);

// Add favorite
$post->addFavorite($user);

// Remove favorite
$post->removeFavorite($user);

// Get favorites count
$post->favoritesCount();

// Query scope for favorited items
Post::favoritedBy($user)->get();
```

Customizing the Favorites List Display
--------------------------------------

[](#customizing-the-favorites-list-display)

To customize how your favorited items appear in the favorites list, implement these methods in your model:

```
class Post extends Model
{
    use Favoritable;

    public function getFavoritableTitle(): string
    {
        return $this->title;
    }

    public function getFavoritableDescription(): ?string
    {
        return $this->excerpt;
    }

    public function getFavoritableImage(): ?string
    {
        return $this->featured_image;
    }

    public function getFavoritableUrl(): string
    {
        return route('posts.show', $this);
    }
}
```

Configuration
-------------

[](#configuration)

The package includes a configuration file with sensible defaults:

```
return [
    // The fully qualified class name of the user model
    'user_model' => env('FAVORITABLE_USER_MODEL', 'App\\Models\\User'),

    // The name of the belongTo relationship on the favoritable model to the user model
    'owner_relationship_name' => env('FAVORITABLE_OWNER_RELATIONSHIP_NAME', 'user'),

    // Button configuration
    'button' => [
        'default_variant' => 'default',
        'default_size' => 'md',
        'show_count' => true,
    ],

    // List configuration
    'list' => [
        'per_page' => 12,
    ],
];
```

Events
------

[](#events)

The package dispatches Livewire events that you can listen to:

### `favoriteToggled`

[](#favoritetoggled)

Dispatched when a favorite is toggled:

```
Livewire.on('favoriteToggled', (data) => {
    console.log(data.modelType);
    console.log(data.modelId);
    console.log(data.isFavorited);
});
```

Testing
-------

[](#testing)

The package includes comprehensive Pest tests. To run tests:

```
composer test
```

Styling
-------

[](#styling)

The package uses Tailwind CSS for styling. All styles are scoped to avoid conflicts with your application. You can customize the appearance by:

1. Publishing the views and modifying the Blade templates
2. Overriding the CSS classes in your application's CSS
3. Modifying the published CSS file

Advanced Usage
--------------

[](#advanced-usage)

### Custom Favorite Model

[](#custom-favorite-model)

If you need to extend the Favorite model:

```
use Modularavel\Favoritable\Models\Favorite as BaseFavorite;

class Favorite extends BaseFavorite
{
    // Your custom code
}
```

### Middleware Protection

[](#middleware-protection)

Protect your favorites routes with middleware:

```
Route::middleware(['auth'])->group(function () {
    Route::get('/favorites', function () {
        return view('favorites');
    });
});
```

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

- Modularavel
- All Contributors

Support
-------

[](#support)

For issues, questions, or contributions, please visit the GitHub repository.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance69

Regular maintenance activity

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

211d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7354fd72dfef31d8a9afddab61122ab6ade014057993e0c05b1f7e0d95343742?d=identicon)[modularavel](/maintainers/modularavel)

---

Top Contributors

[![casimirorocha](https://avatars.githubusercontent.com/u/6707152?v=4)](https://github.com/casimirorocha "casimirorocha (10 commits)")[![modularavel](https://avatars.githubusercontent.com/u/149928614?v=4)](https://github.com/modularavel "modularavel (1 commits)")

---

Tags

laravellivewireFavoritesfavoritablemodularavel

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/modularavel-favoritable/health.svg)

```
[![Health](https://phpackages.com/badges/modularavel-favoritable/health.svg)](https://phpackages.com/packages/modularavel-favoritable)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M681](/packages/barryvdh-laravel-ide-helper)[livewire/flux

The official UI component library for Livewire.

9385.0M85](/packages/livewire-flux)[mediconesystems/livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS

1.2k711.3k8](/packages/mediconesystems-livewire-datatables)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)[tanthammar/livewire-window-size

Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css. Requires Livewire and AlpineJS

2321.0k](/packages/tanthammar-livewire-window-size)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
