PHPackages                             tobento/app-card - 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. tobento/app-card

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

tobento/app-card
================

App card support.

2.0.1(6mo ago)0212MITPHPPHP &gt;=8.4

Since Apr 11Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/app-card)[ Packagist](https://packagist.org/packages/tobento/app-card)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-app-card/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (5)Dependencies (11)Versions (7)Used By (2)

App Card
========

[](#app-card)

The card app provides interfaces to create cards to be displayed on a dashboard page for instance. It comes with a default implementation and basic [cards](#cards).

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

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Card Boot](#card-boot)
        - [Card Config](#card-config)
    - [Cards](#cards)
        - [Adding Cards](#adding-cards)
        - [Cards Methods](#cards-methods)
        - [Displaying Cards In Views](#displaying-cards-in-views)
        - [Creating Specific Cards](#creating-specific-cards)
    - [Available Cards](#available-cards)
        - [Chart Card](#chart-card)
        - [Group Card](#group-card)
        - [Html Card](#html-card)
        - [KeyedList Card](#keyedlist-card)
        - [Table Card](#table-card)
    - [Available Card Factories](#available-card-factories)
        - [Chart Card Factory](#chart-card-factory)
        - [Group Card Factory](#group-card-factory)
        - [Html Card Factory](#html-card-factory)
        - [KeyedList Card Factory](#keyedlist-card-factory)
        - [Table Card Factory](#table-card-factory)
    - [Filterable Cards](#filterable-cards)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the app card project running this command.

```
composer require tobento/app-card

```

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

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

Card Boot
---------

[](#card-boot)

The card boot does the following:

- migrates card config, view and asset files
- implements cards interfaces based on the card config file

```
use Tobento\App\AppFactory;
use Tobento\App\Card\CardsInterface;
use Tobento\App\Card\FilterInputInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Card\Boot\Card::class);
$app->booting();

// Implemented interfaces:
$cards = $app->get(CardsInterface::class);
$filterInput = $app->get(FilterInputInterface::class);

// Run the app
$app->run();

```

### Card Config

[](#card-config)

The configuration for the card is located in the `app/config/card.php` file at the default App Skeleton config location where you can configure the implemented card interfaces for your application.

Cards
-----

[](#cards)

### Adding Cards

[](#adding-cards)

You may use the implemented `CardsInterface::class` adding cards to [display them later in your view files](#displaying-cards-in-views) or you may [create your own cards specific to a resource](#creating-specific-cards).

Furthermore, it is recommended to use the [App on](https://github.com/tobento-ch/app#on) method to add cards only if requested.

```
use Tobento\App\Card\Card;
use Tobento\App\Card\CardInterface;
use Tobento\App\Card\CardsInterface;
use Tobento\App\Card\Factory;
use Tobento\Service\View\ViewInterface;

$app->on(
    CardsInterface::class,
    static function(CardsInterface $cards): void {
        // Using a card factory:
        $cards->add(name: 'foo', card: new Factory\Table(
            rows: [['foo']],
        ));

        // Using a callable being autowired:
        $cards->add(
            name: 'foo',
            card: static function (string $name, ViewInterface $view): CardInterface {
                return new Card\Table(
                    view: $view,
                    rows: [['foo']],
                );
            }
        );

        // Using a card instance:
        $cards->add(name: 'foo', card: new SomeCard());

        // Using a card class string being autowired:
        $cards->add(name: 'foo', card: SomeCard::class);
    }
);

```

Check out the [Available Cards](#available-cards) or [Available Card Factories](#available-card-factories).

### Cards Methods

[](#cards-methods)

**Filter Methods**

You may filter added cards using the following methods returning a new instance:

```
use Tobento\App\Card\CardInterface;

// Returns a new instance with the filtered cards.
$cards = $cards->filter(fn(CardInterface $c): bool => $c->priority() > 1);

// Returns a new instance with the specified group filtered.
$cards = $cards->group(name: 'name');

// Returns a new instance with only the card(s) specified.
$cards = $cards->only('foo', 'bar');

// Returns a new instance except the specified card(s).
$cards = $cards->except('foo', 'bar');

```

**Retrieving Methods**

```
// Returns true if card exists, otherwise false.
$cards->has(name: 'foo');

// Returns a card by name or null if not exists.
$card = $cards->get(name: 'foo');

// Returns all card names.
$cardNames = $cards->names();

// Returns the number of cards (int).
$numberOfCards = $cards->count();

// Returns all cards.
$cards = $cards->all(); // array

// Iterating cards.
foreach($cards as $card) {}

```

### Displaying Cards In Views

[](#displaying-cards-in-views)

In your view file, use the render method to display the cards:

```
