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

Crud Bundle Laravel Package

araise/crud-bundle

View on GitHub
Deep Wiki
Context7

View Definition

Prefill a relation field in forms

You can define which data row the definition uses as the default value of an input field. This way you can either give the user advice on what you think might be right in this situation or, if you hide the input field, you can automatically fill in the correct relation for the user without him having to do anything.

As an example we use an imaginary Book/Author management software: We would like to add a button to an authors page that allows us to create a new book with the author already prefilled. In order to achieve this, we need to add the Content::OPT_PRESELECT_DEFINITION and the class form option to the content of the BookDefinition like so:

// BookDefinition
public function configureView(DefinitionBuilder $builder, $data): void
{
    parent::configureView($builder, $data);

    $builder
        ->addBlock('base')
        ->addContent('author', null, [
            Content::OPT_DEFAULT_VALUE => $entity->getAuthor(),
            Content::OPT_PRESELECT_DEFINITION => AuthorDefinition::class,
            Content::OPT_FORM_OPTIONS => [
                'class' => Author::class,
            ],
        ])
    ;
}

Linking to the prefilled form

On the other side, in the AuthorDefinition, we can now create the link to this page like so:

// AuthorDefinition
public function configureActions(mixed $data): void
{
    parent::configureActions($data);

    if ($data && $this->getPage() === Page::SHOW)
    {
        $this->addAction('add_book', [
            'route' => BookDefinition::getRoute(Page::CREATE),
            'route_parameters' => [
                self::getQueryAlias() => $data->getId(),
            ],
        ]);
    }
}

This adds a button on the detail page of an author that links to the create page of a book with the author preselected.

Hiding the input field

If you want to hide the input field in the form, you can do so by using the EntityHiddenType as the form type like so:

// BookDefinition
public function configureView(DefinitionBuilder $builder, $data): void
{
    parent::configureView($builder, $data);

    $builder
        ->addBlock('base')
        ->addContent('author', null, [
            Content::OPT_DEFAULT_VALUE => $entity->getAuthor(),
            Content::OPT_PRESELECT_DEFINITION => AuthorDefinition::class,
            Content::OPT_FORM_OPTIONS => [
                'class' => Author::class,
            ],
            Content::OPT_FORM_TYPE => EntityHiddenType::class,
        ])
    ;
}

This way the user will not see the input field but the value will still be prefilled.

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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware