Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sharp Laravel Package

code16/sharp

Code-driven CMS framework for Laravel (PHP 8.3+/Laravel 11+). Build admin/CMS sections with a clean UI and strong DX: CRUD with validation, search/sort/filter, bulk or custom commands, and authorization—no front-end code required, data-agnostic.

View on GitHub
Deep Wiki
Context7

Html

Class: Code16\Sharp\Form\Fields\SharpFormHtmlField

This field is read-only, and is meant to display some dynamic information in the form.

Configuration

setTemplate(string|View|Closure $template)

Write the blade template as a string. Example:

SharpFormHtmlField::make('panel')
    ->setTemplate('This product is offline since <strong>{{ $date }}</strong>')

This example would mean that your transformed data has an object named panel containing a date attribute. Here a custom transformer example for this particular case:

function find($id): array
{
    return $this
        ->setCustomTransformer('panel', fn ($value, $instance) => [
            'date' => $instance->deprecated_at->isoFormat()
        ])
        ->transform(Product::find($id));
}

You can also pass a view (blade) :

SharpFormHtmlField::make('panel')
    ->setTemplate(view('sharp.form-htm-field'))

Using a closure:

SharpFormHtmlField::make('panel')
    ->setTemplate(function (array $data) {
        return 'You have chosen:'.$data['another_form_field'].'. Date: '.$data['date'];
    })

Accessing to other field values in the form

In the template, all other field values of the form are available (alongside the Html field value). This is particularly useful when using setLiveRefresh() (described below).

setLiveRefresh(bool $liveRefresh = true, ?array $linkedFields = null)

Use this method to dynamically update Html field when the user changes another field. The $linkedFields parameter allows filtering which field to watch (without it the internal refresh endpoint is called on any field update).

SharpFormHtmlField::make('total')
    ->setLiveRefresh(linkedFields: ['products'])
    ->setTemplate(function (array $data) {
        return 'Total:'.collect($data['products'])
            ->sum(fn ($product) => $product['price']);
    })

Formatter

  • toFront: sent as provided.
  • fromFront: returns null (read-only).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle