Skip to content

Instantly share code, notes, and snippets.

@sabid
Created November 13, 2019 20:40
Show Gist options
  • Save sabid/53df3291955bd4640f8a430d63988a7a to your computer and use it in GitHub Desktop.
Save sabid/53df3291955bd4640f8a430d63988a7a to your computer and use it in GitHub Desktop.
Laravel Key Value From Collection
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