Search by

itstructure / laravel-detail-view

itstructure

Detail view table for Laravel: show an Eloquent model, an array or an object as a table of attributes and values

Package info

github.com/itstructure/laravel-detail-view

pkg:composer/itstructure/laravel-detail-view

Statistics

Installs: 7 302

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.1.0 2026-12-01 14:22 UTC

This package is auto-updated.

Last update: 2026-12-01 14:31:25 UTC


README

Latest Stable Version Latest Unstable Version License Total Downloads Build Status Scrutinizer Code Quality Tests

Introduction

This package shows data of one record as a table: a row for each attribute, with a label and a value. The data can be an Eloquent model, an array or an object.

It works with any CSS framework: the package does not add its own classes, you set them in the config. For example table table-bordered table-striped for Bootstrap 4 or 5.

Detail view appearance

Requirements

  • laravel 5.5+ | 6+ | 7+ | 8+ | 9+ | 10+ | 11+ | 12+ | 13+
  • php >= 7.1
  • composer

The package has no other dependencies.

Installation

General from remote packagist repository

Run the composer command:

composer require itstructure/laravel-detail-view "^1.1.0"

If you are testing this package from a local server directory

In application composer.json file set the repository, as in example:

"repositories": [
    {
        "type": "path",
        "url": "../laravel-detail-view",
        "options": {
            "symlink": true
        }
    }
],

Here,

../laravel-detail-view - directory path, which has the same directory level as application and contains Detail View package.

Then run command:

composer require itstructure/laravel-detail-view:dev-main --prefer-source

Publish files (Not necessary)

  • To publish views run command:

    php artisan detail_view:publish --only=views

    It stores view files to resources/views/vendor/detail_view folder.

  • To publish translations run command:

    php artisan detail_view:publish --only=lang

    It stores translation files to resources/lang/vendor/detail_view folder.

  • To publish all parts run command without only argument:

    php artisan detail_view:publish

    Else you can use --force argument to rewrite already published files.

Else you can use --force argument to rewrite already published file.

Usage

View template part

Use @detailView() directive with config array in a blade view template.

Simple quick usage

You can simply set rows to display as string format in rowFields array.

Note: $model can be an Eloquent model (Illuminate\Database\Eloquent\Model), an array or an object. See Arrays and objects below.

@php
$detailData = [
    'model' => $model,
    'title' => 'Detail table',
    'rowFields' => [
        'id',
        'active',
        'icon',
        'created_at'
    ]
];
@endphp
@detailView($detailData)

Alternative variant without a blade directive:

{!! detail_view([
    'model' => $model,
    'title' => 'Detail table',
    'rowFields' => [
        'id',
        'active',
        'icon',
        'created_at'
    ]
]) !!}

Setting custom options

Rows

Simple example:

@detailView([
    'model' => $model,
    'rowFields' => [
        [
            'label' => 'First Name', // Row label.
            'attribute' => 'first_name', // Attribute, by which the row data will be taken from a model.
        ],
        [
            'label' => 'Last Name',
            'value' => function ($model) {
                return $model->last_name;
            }
        ],
    ]
])
Arrays and objects

Since version 1.1.0 the model option can be an array or an object, not only an Eloquent model. For example, data from an API, a config or a DTO:

@detailView([
    'model' => [
        'name' => 'Apple',
        'price' => 10,
        'address' => ['city' => 'Minsk'],
    ],
    'rowFields' => [
        'name',
        'price',
        [
            'label' => 'City',
            'attribute' => 'address.city', // A dot notation for nested arrays and objects
        ],
        [
            'label' => 'Price with tax',
            'value' => function ($data) { // The callback gets the same array or object
                return $data['price'] * 2;
            },
        ],
    ]
])

A missing key or property is shown as an empty value.

If you have your own row class (extended from BaseRow), it works with Eloquent models as before. To show arrays and objects with it, override the getDataValue($data) method.

Formatters

There are the next formatter keys:

  • html - is for passing a row content with html tags. The value is not escaped, so use it only for trusted content.
  • image - is for inserting a row data in to src attribute of <img> tag. The value is escaped.
  • text - the default formatter. It removes html tags with strip_tags() and escapes special characters (&, <, >, quotes). If allowableTags option is set, the allowed tags stay and the value is not escaped.
  • url - is for inserting a row data in to href attribute of <a> tag. The value is escaped. The title option (a link text) is not escaped, so it can contain html, like an icon.

For that keys there are the next formatters:

  • HtmlFormatter
  • ImageFormatter
  • TextFormatter
  • UrlFormatter

Also you can set formatter with some addition options. See the next simple example:

@detailView([
    'model' => $model,
    'rowFields' => [
        [
            'attribute' => 'url',
            'format' => [
                'class' => Itstructure\DetailView\Formatters\UrlFormatter::class,
                'title' => 'Source',
                'htmlAttributes' => [
                    'target' => '_blank'
                ]
            ]
        ],
        [
            'attribute' => 'content',
            'format' => 'html'
        ]
    ]
])
Table heads

To set column titles, you can set captionColumnConfig and valueColumnConfig as in example:

@detailView([
    'model' => $model,
    'captionColumnConfig' => [
        'label' => 'Custom title column',
        'htmlAttributes' => [
            'class' => 'th-title-class'
        ]
    ],
    'valueColumnConfig' => [
        'label' => 'Custom value column',
        'htmlAttributes' => [
            'class' => 'th-value-class'
        ]
    ],
    'rowFields' => [
        [
            'attribute' => 'content',
        ]
    ]
])

To hide all table row with head titles:

@detailView([
    'model' => $model,
    'showHead' => false,
    'rowFields' => [
        [
            'attribute' => 'content',
        ]
    ]
])
Complex extended example
@php
$detailData = [
    'model' => $model,
    'title' => 'Detail title', // It can be empty ''
    'htmlAttributes' => [
        'class' => 'table table-bordered table-striped'
    ],
    'captionColumnConfig' => [
        'label' => 'Custom title column',
        'htmlAttributes' => [
            'class' => 'th-title-class'
        ]
    ],
    'valueColumnConfig' => [
        'label' => 'Custom value column',
        'htmlAttributes' => [
            'class' => 'th-value-class'
        ]
    ],
    'rowFields' => [
        [
            'attribute' => 'id', // REQUIRED if value is not defined. Attribute name to get row model data.
            'label' => 'ID', // Row label.
            'htmlAttributes' => [
                'class' => 'tr-class'
            ]
        ],
        [
            'label' => 'Active', // Row label.
            'value' => function ($model) { // You can set 'value' as a callback function to get a row data value dynamically.
                return '<span class="icon fas '.($model->active == 1 ? 'fa-check' : 'fa-times').'"></span>';
            },
            'format' => 'html', // To render row content without lossless of html tags, set 'html' formatter.
        ],
        [
            'label' => 'Url link', // Row label.
            'attribute' => 'url', // REQUIRED if value is not defined. Attribute name to get row model data.
            'format' => [ // Set special formatter. $model->{$this->attribute} will be inserted in to 'href' attribute of <a> tag.
                'class' => Itstructure\DetailView\Formatters\UrlFormatter::class, // REQUIRED. For this case it is necessary to set 'class'.
                'title' => 'Source', // title between a tags.
                'htmlAttributes' => [ // Html attributes for <a> tag.
                    'target' => '_blank'
                ]
            ]
        ],
        [
            'label' => 'Icon', // Row label.
            'value' => function ($model) { // You can set 'value' as a callback function to get a row data value dynamically.
                return $model->icon;
            },
            'format' => [ // Set special formatter. If $model->icon value is a url to image, it will be inserted in to 'src' attribute of <img> tag.
                'class' => Itstructure\DetailView\Formatters\ImageFormatter::class, // REQUIRED. For this case it is necessary to set 'class'.
                'htmlAttributes' => [ // Html attributes for <img> tag.
                    'width' => '100'
                ]
            ]
        ],
        'created_at', // Simple row setting by string.
    ]
];
@endphp
@detailView($detailData)

Note: the title option is not escaped, so it can contain html. Do not put a user input there without escaping.

Tests

The package has its own tests. They check rows, Eloquent models, arrays and objects, formatters, html attributes, the @detailView directive and the publish command.

Good to know before you start:

  • The tests do not need a database server and do not need a .env file. They use SQLite in memory, everything is created and deleted automatically.
  • The tests work on all supported versions: PHP 7.1 ... 8.5 and Laravel 5.5 ... 13.
  • When you install dependencies of the package, the vendor folder and the composer.lock file appear in the package folder. It is normal. They are in .gitignore, so they will not get into git.

Below there are several ways to run the tests. Choose the one, which fits you.

Way 1. You have PHP and Composer on your computer

  1. Get the package source code.

    If you have git, run command:

    git clone https://github.com/itstructure/laravel-detail-view.git

    If you do not have git, open https://github.com/itstructure/laravel-detail-view, press the green Code button, then Download ZIP, and unpack the archive.

  2. Go to the package folder:

    cd laravel-detail-view

  3. Install dependencies (it is enough to do it once):

    composer install

    Composer itself chooses the Laravel and PHPUnit versions, which fit your PHP version.

    Note! PHP must have pdo_sqlite and mbstring extensions. Usually they are already enabled. If not, Composer or the tests will tell you about it.

  4. Run the tests:

    composer test

    Or the same directly:

    • Linux / macOS: vendor/bin/phpunit
    • Windows: vendor\bin\phpunit
  5. If you want to run only one test, add --filter with the test name:

    vendor/bin/phpunit --filter test_array

If everything is fine, you will see a message like: OK (31 tests, 56 assertions).

Way 2. You have nothing except Docker

You do not need to install PHP and Composer. Docker downloads them by itself.

  1. Get the package source code and go to the package folder, as in steps 1 and 2 of Way 1.

  2. Install dependencies (it is enough to do it once).

    For Linux, macOS and WSL terminal:

    docker run --rm --user "$(id -u):$(id -g)" -e COMPOSER_HOME=/tmp/composer -v "$PWD":/app -w /app composer:2 composer update --no-interaction

    For Windows PowerShell:

    docker run --rm -v "${PWD}:/app" -w /app composer:2 composer update --no-interaction

    Here:

    • --user "$(id -u):$(id -g)" - files in the vendor folder will belong to you, not to the root user. In Windows PowerShell it is not needed.
    • -v "$PWD":/app - the current folder (package folder) is available inside the container as /app.
  3. Run the tests.

    For Linux, macOS and WSL terminal:

    docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/app -w /app php:8.4-cli php vendor/bin/phpunit

    For Windows PowerShell:

    docker run --rm -v "${PWD}:/app" -w /app php:8.4-cli php vendor/bin/phpunit

    To run only one test, add --filter test_name to the end of the command.

Note! In step 2 Composer installs the newest versions of Laravel and PHPUnit. They need a new PHP, so in step 3 use php:8.4-cli or newer. To check an old PHP or Laravel version, see Way 3.

Way 3. Check a specific PHP and Laravel version with Docker

It is useful, when you want to make sure that the package works for example on PHP 7.3 with Laravel 8.

  1. Choose a pair of versions from the table:

    PHP image Laravel Testbench
    php:7.1-cli 5.5.* 3.5.*
    php:7.2-cli 5.8.* 3.8.*
    php:7.2-cli 6.* 4.*
    php:7.3-cli 7.* 5.*
    php:7.3-cli 8.* 6.*
    php:8.0-cli 9.* 7.*
    php:8.1-cli 10.* 8.*
    php:8.2-cli 11.* 9.*
    php:8.3-cli 12.* 10.*
    php:8.3-cli 13.* 11.*

    Testbench (orchestra/testbench) is a tool for testing Laravel packages. Each Laravel version needs its own Testbench version, that is why it is in the table.

  2. Go to the package folder. If you have already installed dependencies before, delete the vendor folder and the composer.lock file.

  3. Install dependencies for the chosen pair. Example for PHP 7.3 + Laravel 8 (Linux, macOS, WSL terminal):

    docker run --rm --user "$(id -u):$(id -g)" -e COMPOSER_HOME=/tmp/composer -v "$PWD":/app -w /app composer:2 sh -c "composer config platform.php 7.3.33 && composer config policy.advisories.block false && composer require --no-update 'laravel/framework:8.*' && composer require --dev --no-update 'orchestra/testbench:6.*' && composer update --no-interaction --no-plugins"

    What this command does:

    • composer config platform.php 7.3.33 - tells Composer to choose packages for PHP 7.3, because Composer itself works on a newer PHP inside its container.
    • composer config policy.advisories.block false - allows installing old Laravel versions. New Composer refuses to install versions with known security advisories. It is OK for running tests, but never do it in a real project.
    • composer require --no-update ... - sets the chosen Laravel and Testbench versions.
    • --no-plugins - old Laravel versions bring Composer plugins, which are not needed for tests and are blocked by new Composer.

    For another pair, change 7.3.33, 8.* and 6.* to the values from the table. For platform.php you can write any version of the chosen PHP, for example 7.1.33, 8.0.30, 8.2.0.

  4. Run the tests with the PHP image from the table:

    docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/app -w /app php:7.3-cli php vendor/bin/phpunit
  5. Important! The command in step 3 changes the composer.json file of the package. When you finish, return it back and delete the installed files:

    git checkout composer.json

    And delete the vendor folder and the composer.lock file.

    If you downloaded the package as ZIP (without git), just download and unpack it again.

Way 4. Automatic tests on GitHub

You do not need to do anything. After each push and each pull request, GitHub runs the tests by itself on all version pairs from the table above (and a few more).

Results are on the Actions tab of the repository: https://github.com/itstructure/laravel-detail-view/actions

Green check mark - all tests passed. Red cross - something is broken, open it to see the details.

The settings are in the .github/workflows/tests.yml file.

If the package is installed in your Laravel project

  1. Your project tests and the package tests do not mix.

    When you run tests of your project (composer test, php artisan test or vendor/bin/phpunit in the project folder), only tests of your project are run. The project phpunit.xml file points to the project tests folder, and the package lies in vendor/itstructure/laravel-detail-view. So the package tests are not run there.

  2. Usually there are no package tests in your project at all.

    By default Composer downloads the package as an archive. The tests folder, the .github folder and the phpunit.xml.dist file are excluded from this archive (see the .gitattributes file), because they are not needed for the package to work. So in vendor/itstructure/laravel-detail-view there is only the package itself.

  3. Exception: installation with --prefer-source.

    If the package is installed with --prefer-source (Composer makes git clone instead of downloading an archive), or from a local folder (see "If you are testing this package from a local server directory" above), then the whole repository is in the project, the tests too.

    It does not break anything: your project tests still do not run them.

  4. How to run the package tests in this case.

    Do not run them through your project, the project has no tools needed for the package tests.

    Run them in the package folder itself, as described in Way 1 or Way 2:

    • If the package is installed from a local folder ("type": "path"), go to that local folder, for example ../laravel-detail-view.
    • Otherwise, just clone the package repository to a separate folder.

License

Copyright © 2021-2026 Andrey Girnik girnikandrey@gmail.com.

Licensed under the MIT license. See LICENSE.txt for details.