PHP code example of jeffersonsimaogoncalves / nova-enum-field

1. Go to this page and download the library: Download jeffersonsimaogoncalves/nova-enum-field library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeffersonsimaogoncalves / nova-enum-field example snippets


use App\Enums\UserType;
use BenSampo\Enum\Traits\CastsEnums;
use Illuminate\Database\Eloquent\Model;

class Example extends Model
{
    use CastsEnums;

    protected $casts = [
        'user_type' => UserType::class,
    ];
}

namespace App\Nova;

use App\Enums\UserType;
use SimpleSquid\Nova\Fields\Enum\Enum;

class Example extends Resource
{
    // ...

    public function fields(Request $request)
    {
        return [
            // ...

            Enum::make('User Type')->attach(UserType::class),

            // ...
        ];
    }
}

namespace App\Nova;

use App\Enums\UserPermissions;
use SimpleSquid\Nova\Fields\Enum\FlaggedEnum;

class Example extends Resource
{
    // ...

    public function fields(Request $request)
    {
        return [
            // ...

            FlaggedEnum::make('User Permissions')->attach(UserPermissions::class),

            // ...
        ];
    }
}

namespace App\Nova;

use App\Enums\UserPermissions;
use App\Enums\UserType;
use SimpleSquid\Nova\Fields\Enum\EnumFilter;

class Example extends Resource
{
    // ...

    public function filters(Request $request)
    {
        return [
            new EnumFilter('user_type', UserType::class),
            
            new EnumFilter('user_permissions', UserPermissions::class),
            
            // With optional filter name:
            (new EnumFilter('user_type', UserType::class))
                ->name('Type of user'),
                
             // With optional default value:
            (new EnumFilter('user_type', UserType::class))
                ->default(UserType::Administrator),
        ];
    }
}

namespace App\Nova;

use App\Enums\UserPermissions;
use App\Enums\UserType;
use SimpleSquid\Nova\Fields\Enum\EnumBooleanFilter;

class Example extends Resource
{
    // ...

    public function filters(Request $request)
    {
        return [
            new EnumBooleanFilter('user_type', UserType::class),
            
            new EnumBooleanFilter('user_permissions', UserPermissions::class),
            
            // With optional filter name:
            (new EnumBooleanFilter('user_type', UserType::class))
                ->name('Type of user'),
                
            // With optional default values:
            (new EnumBooleanFilter('user_type', UserType::class))
                ->default([
                    UserType::Administrator,
                    UserType::Moderator,
                ]),
            
            // When filtering a FlaggedEnum, it will default to filtering
            // by ANY flags, however you may wish to filter by ALL flags:
            (new EnumBooleanFilter('user_permissions', UserPermissions::class))
                ->filterAllFlags(),
        ];
    }
}