PHP code example of datomatic / nova-enum-field

1. Go to this page and download the library: Download datomatic/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/ */

    

datomatic / nova-enum-field example snippets


use App\Enums\UserType;
use Illuminate\Database\Eloquent\Model;

class Example extends Model
{
    protected $casts = [
        'user_type' => UserType::class,
    ];
}

namespace App\Nova;

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

class Example extends Resource
{
    // ...

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

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

            // ...
        ];
    }
}

Enum::make('User Type','user_type')
    ->nullable()
    ->property('excerpt')
    ->cases([UserType::ADMINISTRATOR,UserType::MODERATOR])
    ->attach(UserType::class),

namespace App\Nova;

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

class Example extends Resource
{
    // ...

    public function filters(Request $request)
    {
        return [
            EnumFilter::make('user_type', UserType::class),
                
             // With optional name and default value:
            EnumFilter::make('user_type', UserType::class)
                ->name(__('User Type'))
                ->default(UserType::ADMINISTRATOR)
        ];
    }
}

namespace App\Nova;

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

class Example extends Resource
{
    // ...

    public function filters(Request $request)
    {
        return [
            EnumBooleanFilter::make('user_type', UserType::class),
                
            // With optional name and default value:
            EnumBooleanFilter::make('user_type', UserType::class)
                ->name(__('User Type'))
                ->default([UserType::ADMINISTRATOR, UserType::MODERATOR])
        ];
    }
}

// Enum filter
EnumFilter::make('user_type', UserType::class)
    ->name('User Type')
    ->property('excerpt')
    ->cases([UserType::ADMINISTRATOR,UserType::MODERATOR])
// Boolean Enum filter
EnumBooleanFilter::make('user_type', UserType::class)
    ->name('User Type')
    ->property('excerpt')
    ->cases([UserType::ADMINISTRATOR,UserType::MODERATOR])