PHPackages                             lyrasoft/banner - 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/banner

ActiveWindwalker-package

lyrasoft/banner
===============

Luna Banner package

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

Since Aug 1Pushed 6mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (20)Used By (1)

LYRASOFT Banner Package
=======================

[](#lyrasoft-banner-package)

[![screenshot](https://user-images.githubusercontent.com/1639206/182134010-ec900d4c-b2fd-495f-bac0-d9034ce235c4.jpg)](https://user-images.githubusercontent.com/1639206/182134010-ec900d4c-b2fd-495f-bac0-d9034ce235c4.jpg)

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

[](#installation)

Install from composer

```
composer require lyrasoft/banner
```

Then copy files to project

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

Seeders

- Add `contact-seeder.php` to `resources/seeders/main.seeder.php`
- Add `banner` type to `category.seeder.php`

Languages

Run this command to copy language files:

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

If you want to directly use package language files without copy, add this line to admin &amp; front middleware:

```
$this->lang->loadAllFromVendor(\Lyrasoft\Banner\BannerPackage::class, 'ini');
```

Use Type or Category
--------------------

[](#use-type-or-category)

You have 2 choice to structure banners, use `type` or `category`

Type:

[![screenshot 2022-08-27 下午4 51 25](https://user-images.githubusercontent.com/1639206/187023024-762f6b4c-a6db-496e-9ac7-59f337448416.jpg)](https://user-images.githubusercontent.com/1639206/187023024-762f6b4c-a6db-496e-9ac7-59f337448416.jpg)

Category:

[![screenshot 2022-08-27 下午4 52 04](https://user-images.githubusercontent.com/1639206/187023025-33163b4b-140c-4290-a825-20dc0f0f2a06.jpg)](https://user-images.githubusercontent.com/1639206/187023025-33163b4b-140c-4290-a825-20dc0f0f2a06.jpg)

The default will use `category` mode. If you want to use `type` mode, you must create a `BannerType` enum, for example:

```
enum BannerType: string implements EnumRichInterface
{
    use EnumRichTrait;

    #[Title('Home Banner')]
    case HOME = 'home';

    #[Title('Works')]
    case WORKS = 'works';

    // ...
}
```

Then register enum class to config file:

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

        'type_enum' => \App\Enum\BannerType::class,

        // ...
```

The package will auto switch to `type` mode.

Register Admin Menu
-------------------

[](#register-admin-menu)

Edit `resources/menu/admin/sidemenu.menu.php`

Ues Type mode:

```
// Banner
$menu->link('橫幅管理')
    ->to($nav->to('banner_list'))
    ->icon('fal fa-gallery-thumbnails');
```

Use Category mode:

```
// Category
$menu->link('橫幅分類')
    ->to($nav->to('category_list', ['type' => 'banner']))
    ->icon('fal fa-sitemap');

// Banner
$menu->link('橫幅管理')
    ->to($nav->to('banner_list'))
    ->icon('fal fa-images');
```

Add Widget
----------

[](#add-widget)

Add this to `packages/widget.php`

```
return [
    'widget' => [
        'types' => [
            // ...
            'banner' => \Lyrasoft\Banner\Widget\Banner\BannerWidget::class
        ],
        // ...
    ]
];
```

Install `Swiper` and `youtube-background`
-----------------------------------------

[](#install-swiper-and-youtube-background)

After packages installed, it will auto reauire `swiper` as node modules for root `package.json`.

If you needs use video &amp; Youtbue, you must manually install `youtube-background`

```
yarn add youtube-background
```

- Swiper:
    - Getting Started:
    - Demo:
- Youtbue Background
    - Github:

Frontend Usage
--------------

[](#frontend-usage)

Use `BannerRepository` to get banners

```
$repo = $app->service(BannerRepository::class);

/** @var Banner[] $banners */
$banners = $repo->getBannersByType('home')->all();
$banners = $repo->getBannersByCategoryAlias('category-alias')->all();
$banners = $repo->getBannersByCategoryId(5)->all();
```

Then use component in Edge:

```

```

[![2022-08-01 19 05 58](https://user-images.githubusercontent.com/1639206/182135063-62b6fc61-45f2-4f7a-ac80-5f6306d9a829.gif)](https://user-images.githubusercontent.com/1639206/182135063-62b6fc61-45f2-4f7a-ac80-5f6306d9a829.gif)

You can add some params:

```

```

### Parameters

[](#parameters)

Param NameTypeDefaultDescriptionbanners`Banner[]`nullThe banner items, must be a iterable with `Banner` entity.category-alias`?string`nullIf not provides banner items, component will find banners by this condition.category-id`string` or `int`nullIf not provides banner items, component will find banners by this condition.type`string`\_defaultIf not provides banner items, use this type name to find banners &amp; size &amp; ratio settings.link-target`string`nullThe link target, can be `_blank`height`string`nullForce banner height, ignore ratio settings.ratio`float`nullThe widrh / height ratio. for example: 16:9 is `1.7778`. Leave empty yto let component calc it.show-text`bool`falseShow banner title / description or not.options`array`\[\]The options for `Swiper`### Examples

[](#examples)

Load by type

```

```

Load by category alias

```

```

Load by category ID

```

```

Banner Item Slot
----------------

[](#banner-item-slot)

Use `item` slot with `@scope()`, you will get `Banner` entity and index `$i`.

Then just build you own HTML.

```

        @scope($banner, $i)

                {{ $banner->getTitle() }}

```

### Use Banner Item Component

[](#use-banner-item-component)

Use can use `x-banner-item` component, it;s includes default RWD and video switch functions.

```

        @scope($banner, $i)

                {{ $banner->getTitle() }}

```

Parameters:

Param NameTypeDefaultDescriptiontype`string`\_defaultUse this type name to find size &amp; ratio settings.banner`Banner`nullThe banner item, must be a `Banner` entity.link-target`string`nullThe link target, can be `_blank`height`string`nullForce banner height, ignore ratio settings.ratio`float`nullThe widrh / height ratio. for example: 16:9 is `1.7778`. Leave empty yto let component calc it.show-text`bool`falseShow banner title / description or not.The Size Settings.
------------------

[](#the-size-settings)

Open `etc/packages/banner.php`, you will see:

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

        'types' => [
            '_default' => [
                'desktop' => [
                    'width' => 1920,
                    'height' => 800,
                    'crop' => true,
                    'ajax' => false,
                    'profile' => 'image',
                ],
                'mobile' => [
                    'width' => 720,
                    'height' => 720,
                    'crop' => true,
                    'ajax' => false,
                    'profile' => 'image',
                ]
            ]
        ]
    ]
];
```

The `_default` type has 2 sizes settings, `desktop` and `mobile`, this means admin upload images will use this size:

[![screenshot 2022-08-01 下午7 23 22](https://user-images.githubusercontent.com/1639206/182137666-0eef8a27-0f97-4ea1-b4e6-977e03bfe6a9.jpg)](https://user-images.githubusercontent.com/1639206/182137666-0eef8a27-0f97-4ea1-b4e6-977e03bfe6a9.jpg)

You can change all uploading settings here.

### Custom Size for Type or Category Alias

[](#custom-size-for-type-or-category-alias)

If you have a category with alias (`promote`), you can add a `promote` size settings with different size.

```
return [
    'banner' => [
        // ...
        'types' => [
            '_default' => [
                // ...
            ],
            'promote' => [
                'desktop' => [
                    'width' => 800,
                    'height' => 400,
                    'crop' => true,
                    'ajax' => false,
                    'profile' => 'image',
                ],
                'mobile' => [
                    'width' => 200,
                    'height' => 200,
                    'crop' => true,
                    'ajax' => false,
                    'profile' => 'image',
                ]
            ],
        ]
    ]
];
```

Make sure your category alias is same:

[![screenshot 2022-08-01 下午7 28 59](https://user-images.githubusercontent.com/1639206/182138618-4f09226f-a020-43df-b4c9-006190360872.jpg)](https://user-images.githubusercontent.com/1639206/182138618-4f09226f-a020-43df-b4c9-006190360872.jpg)

Then the banners in this category will use the new size:

[![screenshot 2022-08-01 下午7 27 55](https://user-images.githubusercontent.com/1639206/182138449-2b157be9-1943-47ce-a679-62137f5fe1ac.jpg)](https://user-images.githubusercontent.com/1639206/182138449-2b157be9-1943-47ce-a679-62137f5fe1ac.jpg)

Create Default Categories/Type
------------------------------

[](#create-default-categoriestype)

If you use Category mode, you may want to create some default categories in migration:

```
$catMapper = $orm->mapper(Category::class);
$catMapper->createOne(
    [
        'title' => '首頁作品',
        'alias' => 'works',
        'parent_id' => 1
    ]
);
```

If you use Type mode, just change the `BannerType` enum cases:

BannerScript
------------

[](#bannerscript)

Directly use Swiper or Youtube Background

```
use Lyrasoft\Banner\Script\BannerScript;

$app->service(BannerScript::class)->swiper('#swiper', $options);

$app->service(BannerScript::class)->youtubeBackground();
```

Widget
------

[](#widget)

If you ever added `BannerWidget::class` to `widget.php`, you'll see this widget in admin:

[![screenshot 2022-08-01 下午7 31 59](https://user-images.githubusercontent.com/1639206/182139089-363cd0a4-a4d7-476f-974b-4948518b99bc.jpg)](https://user-images.githubusercontent.com/1639206/182139089-363cd0a4-a4d7-476f-974b-4948518b99bc.jpg)

After you added this widget and save. Use this code to render position, for example (`demo` position):

```
service(WidgetService::class);
?>
@if ($widgetService->hasWidgets('demo'))

        @foreach ($widgetService->loadWidgets('demo') as $widget)

        @endforeach

@endif
```

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance67

Regular maintenance activity

Popularity25

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 93.5% 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

Every ~66 days

Recently: every ~137 days

Total

19

Last Release

193d ago

PHP version history (2 changes)1.1.0PHP &gt;=8.2

1.2.0PHP &gt;=8.4.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1639206?v=4)[Simon Asika](/maintainers/asika32764)[@asika32764](https://github.com/asika32764)

---

Top Contributors

[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (58 commits)")[![chokeslam](https://avatars.githubusercontent.com/u/34531644?v=4)](https://github.com/chokeslam "chokeslam (3 commits)")[![yinminc](https://avatars.githubusercontent.com/u/28665511?v=4)](https://github.com/yinminc "yinminc (1 commits)")

---

Tags

luna-package

### Embed Badge

![Health badge](/badges/lyrasoft-banner/health.svg)

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

PHPackages © 2026

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