Weave 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

Search

The CrudBundle uses the araise/search-bundle to enable fulltext search without dependencies. The search bundle is documented in the SearchBundle.

Prerequisites

Enable doctrine functions

Doctrine does not support MATCH AGAINST per default. You can enable it by adding the following lines to your config/packages/doctrine.yaml

doctrine:
    orm:
        dql:
            string_functions:
                MATCH_AGAINST: araise\SearchBundle\Extension\Doctrine\Query\Mysql\MatchAgainst

Next, update your database schema.

php bin/console doctrine:schema:update --force

Search on Definition

Enable fields for indexing

Use the #[Index] annotation in order to enable a field for indexing.

use Doctrine\ORM\Mapping as ORM;
use araise\SearchBundle\Annotation\Index;

#[ORM\Entity]
class Post
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private $id;
    
    #[ORM\Column(type: 'string', length: 255)]
    #[Index]
    private $title;

    #[ORM\Column(type: 'string', length: 255)]
    #[Index]
    private $description;

    // ...
}

After that you have to update your index

php bin/console araise:search:populate

Global Search

The bundle comes already with a predefined Controller.

Controller/SearchController.php

class SearchController extends AbstractController
{
    use SearchTrait;

    public function search(Request $request, SearchManager $searchManager): Response
    {
        $templateParams = $this->getGlobalResults($request, $searchManager);

        return $this->render($this->getSearchTemplate(), $templateParams);
    }
}

If you want to restrict results to certain entities use SearchOptions::OPTION_ENTITIES

$searchParams = $this->getGlobalResults($request, $searchManager, [
    SearchOptions::OPTION_ENTITIES => [
        Post::class,
    ],
]);

Configuration

Templates

Global search form is found here: templates/base.html.twig

{% block search_box %}
    <div class="whatwedo_crud-sidedar flex-shrink-0 flex border-t border-neutral-200 p-4">
        <label for="search" class="sr-only">Search</label>
        <div class="relative rounded-md shadow-sm w-full mt-1 z-0">
            <form action="{{ path('search') }}" method="get">
                <input
                    class="whatwedo_core-input"
                    name="query"
                    value=""
                    autocomplete="off"
                    placeholder="Suche ..."
                    type="text"
                >
            </form>
        </div>
    </div>
{% endblock %}

To customize the search results create a file index.html.twig in templates/bundles/araiseSearchBundle

{% extends '@!araiseSearch/index.html.twig' %}

{% block results %}
    <h1>This is a custom heading</h1>
    {{ parent() }}
{% endblock %}

Index groups

You can define indexing groups and restrict search within these. If not specified the standard group is default

#[Index groups: ['default', 'posts']]
private $title;

#[Index]
private $description;

In the controller set which group(s) you want to include using SearchOptions::OPTION_GROUPS

$searchParams = $this->getGlobalResults($request, $searchManager, [
    SearchOptions::OPTION_GROUPS => [
        'posts'
    ],
]);

Formatters and hooks

You can use custom formatters, pre and post search hooks.

Please check out the SearchBundle documentation for more information.

https://araise-dev.github.io/SearchBundle/#/configuration

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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel