Created
November 13, 2019 20:40
-
-
Save sabid/53df3291955bd4640f8a430d63988a7a to your computer and use it in GitHub Desktop.
Laravel Key Value From Collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vehicle extends Model | |
{ | |
// Types of vehicles | |
const SEDAN = 'sedan'; | |
const TURISMO = 'turismo'; | |
const SUV = 'suv'; | |
const CAMIONETA = 'camioneta'; | |
const FURGONETA = 'furgoneta'; | |
const BUS = 'bus'; | |
const CAMION = 'camión'; | |
public static function getTypes() | |
{ | |
return [ | |
self::SEDAN => ucfirst(self::SEDAN), | |
self::TURISMO => ucfirst(self::TURISMO), | |
self::SUV => ucfirst(self::SUV), | |
self::CAMIONETA => ucfirst(self::CAMIONETA), | |
self::FURGONETA => ucfirst(self::FURGONETA), | |
self::BUS => ucfirst(self::BUS), | |
self::CAMION => ucfirst(self::CAMION), | |
]; | |
} | |
public static function getTypesWithLabel() | |
{ | |
return collect( self::getTypes() )->transform(function ($item, $key) { | |
return [ 'label' => $item, 'key' => $key]; | |
})->values()->all(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment