PHP code example of kwaadpepper / enum

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

    

kwaadpepper / enum example snippets

 php
    Days::mon()
    
 php
    Days::mon()->equals(Days::tue()) // false
    Days::mon()->equals(Days::mon()) // true
    Days::mon()->value === Days::tue()->value // false
    Days::mon()->value === Days::mon()->value // true
    
 php
    echo Days::mon(); // 2
    echo Days::tue(); // 4
    echo Days::mon()->label; // Monday
    
 php
    echo json_encode(Days::mon()); // {"label":"Monday","value":2}
    
 php
   Route::get('/days/{day}', function (Days $day) {
            return response()->json([$day]);
        })->middleware('bindings');
    // OR
    Route::get('/days/{day}', [DayController::class, 'getDay']);
   
 php
   public function getDay(Request $request, Day $day) {
       return response()->json([$day]);
   }