PHPackages                             lyrasoft/favorite - 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. lyrasoft/favorite

ActiveLibrary

lyrasoft/favorite
=================

Lyrasoft Favorite package

1.2.2(6mo ago)01.4k↓50%2[1 issues](https://github.com/lyrasoft/luna-favorite/issues)2MITPHPPHP &gt;=8.4.6

Since Feb 27Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/lyrasoft/luna-favorite)[ Packagist](https://packagist.org/packages/lyrasoft/favorite)[ RSS](/packages/lyrasoft-favorite/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (2)

LYRASOFT Favorite Package
=========================

[](#lyrasoft-favorite-package)

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

[](#installation)

Install from composer

```
composer require lyrasoft/favorite
```

Then copy files to project

```
php windwalker pkg:install lyrasoft/favorite -t routes -t migrations
```

This package has no seeders, you must add your own seeders.

### Language Files

[](#language-files)

Add this line to admin &amp; front middleware if you don't want to override languages:

```
$this->lang->loadAllFromVendor(\Windwalker\Language\LanguagePackage::class, 'ini');
```

Or run this command to copy languages files:

```
php windwalker pkg:install lyrasoft/favorite -t lang
```

Seeders
-------

[](#seeders)

Write your own seeders with different `type`:

```
use Lyrasoft\Favorite\Entity\Favorite;

$mapper = $orm->mapper(Favorite::class);

foreach ($faker->randomElements($items, 5) as $item) {
    $favorite = new Favorite();
    $favorite->setType('item');
    $favorite->setUserId($user->getId());
    $favorite->setTargetId($item->getId());

    $mapper->createOne($favorite);
}
```

Add AJAX Buttons
----------------

[](#add-ajax-buttons)

You can add button component in blade templates:

```

        ...

```

in page ts file

```
import { useFavoriteButton } from '@lyrasoft/favorite';

await useFavoriteButton();
```

Available params:

NameTypeDescription`type`stringThe favorite type`id`string or intThe item ID`added`bool or intCurrent is favorited or not in this page.`class-active`stringThe button class if favorited.`class-inactive`stringThe button class if not favorited.`icon-active`stringThe icon class if favorited.`icon-inactive`stringThe button class if not favorited.`title-active`stringThe tooltip title if favorited.`title-inactive`stringThe tooltip title if not favorited.### AJAX Type Protect

[](#ajax-type-protect)

By default, favorite package will not allow any types sent from browser.

You can configre allowed types in config file:

```
return [
    'favorite' => [
        // ...

        'ajax' => [
            'type_protect' => true,
            'allow_types' => [
                'article',
                '...' //
