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

Concord Laravel Package

konekt/concord

Laravel extension for building modular applications using conventions on top of service providers. Manage in-app and external modules with isolation-friendly structure, version compatibility across Laravel releases, and tooling around module registration and organization.

View on GitHub
Deep Wiki
Context7

Enums

Concord internally uses the konekt enum library, so enums are available when using Concord.

Other than what the library provides out of the box, Concord also gives some nice additions to enums.

Registering Enums

Enums provided by modules need to be registered with Concord in order to use its utilities.

Registering can be done in the module/box service provider, by adding the enum class's name to the $enums protected property:

// ModuleServiceProvider.php

namespace App\Modules\Booking\Providers;

use App\Modules\Booking\Models\BedType;
use Konekt\Concord\BaseModuleServiceProvider;

class ModuleServiceProvider extends BaseModuleServiceProvider
{
    protected $enums = [
        BedType::class
    ];
}

Extending Enums

In case you want to extend an enum that was registered by another module these are the steps to do so:

  1. Extend the class
  2. Define new const values
  3. Register your class with Concord for the Enum's interface

Example:

// The original enum class in an underlying module:
namespace Vendor\Module\Models;

class OriginalEnum extends \Konekt\Enum\Enum
{
    const FUBANG = 'fubang';
    const ZDOINK = 'zdoink';
}
// Extend the class and define new const values
namespace App;

class YourEnum extends \Vendor\Module\Models\OriginalEnum
{
    const SPLASH  = 'splash';
}

Register with concord:

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->app->concord->registerEnum(
            \Vendor\Module\Contracts\OriginalEnum::class,
            \App\YourEnum::class
        );
    }
}

This way:

  1. all the underlying models using the original enum will use your enum instead
  2. The enum proxy will resolve to your enum class.
use Vendor\Module\Models\OriginalEnumProxy;

echo OriginalEnumProxy::enumClass();
// output: App\YourEnum

$fubang = OriginalEnumProxy::create('fubang');

echo get_class($fubang);
// output: App\YourEnum
echo $fubang->value();
// output: fubang

$splash = OriginalEnumProxy::create('splash');
echo $splash->value();
// output: splash

Enum Proxies

Using this technique you can define the basic variant of your enum in your module and it can be extended later.

Enum Helper Function

It's possible to resolve enums with their short names via the enum() helper function.

It's mainly useful in blade or other templates that you don't want to mess up with long, fully qualified classnames:

<select>
    [@foreach](https://github.com/foreach)(enum('bed_type')->choices as $key => $value)
    <option value="{{ $key }}">{{ $value }}</option>
    [@endforeach](https://github.com/endforeach)
</select>

It's also possible to provide the value of the enum:

$male = enum('gender', 'm');

Next: Event-Listener Bindings »

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4