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

Sharp is a Laravel 11+ (PHP 8.3+) content management framework for building a CMS/admin area with a clean UI and great DX. Code-driven, data-agnostic, no frontend to write. Manage structured data with search, filters, commands, auth, and validation.

View on GitHub
Deep Wiki
Context7

sidebarDepth: 3

Using Single Form for unique resources

Sometimes you will need to configure a "unique" resource that does not fit into a List / Form schema, like for example an account, or a configuration item. Single Forms are the natural companions for Single Shows, documented here.

Write the class

Instead of extending SharpForm, our SingleForm implementation should extend Code16\Sharp\Form\SharpSingleForm. We still have to implement buildFormFields(FieldsContainer $formFields) and buildFormLayout(FormLayout $formLayout) to declare the fields presenting the instance, but other methods are a bit different. First, find() and update() don't need any $instanceId parameter:

  • findSingle(): array
  • updateSingle(array $data)

Full example

Let's write a Single Form for the current User, where he can update its name and email (using WithSharpFormEloquentUpdater here as this example uses Eloquent):

class AccountSharpForm extends SharpSingleForm
{
    use WithSharpFormEloquentUpdater;

    function buildFormFields(FieldsContainer $formFields): void
    {
        $formFields
            ->addField(
                SharpFormTextField::make('name')
                    ->setLabel('Name')
            )
            ->addField(
                SharpFormTextField::make('email')
                    ->setLabel('Email address')
            );
    }

    function buildFormLayout(FormLayout $formLayout): void
    {
        $formLayout->addColumn(6, function ($column) {
            return $column
                ->withField('name')
                ->withField('email');
        });
    }

    protected function findSingle()
    {
        return $this->transform(
            User::findOrFail(auth()->id())
        );
    }

    protected function updateSingle(array $data)
    {
        return $this->save(
            User::findOrFail(auth()->id()), 
            $data
        )->id;
    }
}

How to declare it?

Like said before, Single Forms will only work in pair with a Single Show; please refer to this documentation to find out how to declare a single show and form.

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.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme