Merge branch 'enums' into 'laravel-10'

add enums

See merge request ldc-web/projets/wenn-dann-mit-respekt!4
This commit is contained in:
Vincent BRIDIER 2023-03-15 11:28:14 +00:00
commit 1beaeece03
9 changed files with 243 additions and 106 deletions

View file

View file

@ -0,0 +1,36 @@
<?php
namespace App\Enums\Concepts;
enum ColorsEnum  : int {
case redwine = 1;
case orange = 2;
case blue = 3;
case lightgreen = 4;
case brown = 5;
public function color(): string {
return static::getColor($this);
}
public static function getColor(self $value): string {
return match ($value) {
self::redwine => rgb(165 25 60),
self::orange => rgb(240 165 0),
self::blue => rgb(95 155 210),
self::lightgreen => rgb(180 190 0),
self::brown => rgb(95 40 45),
};
}
public static function getColors(): array {
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"color" => $value->color()
]]);
}
return $arrayEnum;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace App\Enums\Products;
enum CertificationsEnum : int {
case haltungsform1 = 1;
case haltungsform2 = 2;
case haltungsform3 = 3;
case haltungsform4 = 4;
case ecc = 5;
public function label(): string {
return static::getLabel($this);
}
public function image(): string {
return static::getImage($this);
}
public static function getLabel(self $value): string {
return match ($value) {
self::haltungsform1 => __('Haltungsform 1'),
self::haltungsform2 => __('Haltungsform 2'),
self::haltungsform3 => __('Haltungsform 3'),
self::haltungsform4 => __('Haltungsform 4'),
self::ecc => __('ECC'),
};
}
public static function getImage(self $value): string {
return match ($value) {
self::haltungsform1 => "haltungsform1.png",
self::haltungsform2 => "haltungsform2.png",
self::haltungsform3 => "haltungsform3.png",
self::haltungsform4 => "haltungsform4.png",
self::ecc => "ecc.png",
};
}
public static function getLabels(): array {
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"label" => $value->label(),
"image" => $value->image()
]]);
}
return $arrayEnum;
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace App\Enums\Ranges;
enum PictosEnum  : int {
case chicken = 1;
case duck = 2;
case turkey = 3;
case soupchicken = 4;
case guineafowl = 5;
case goose = 5;
public function label(): string {
return static::getLabel($this);
}
public function image(): string {
return static::getImage($this);
}
public static function getLabel(self $value): string {
return match ($value) {
self::chicken => __('Chicken'),
self::duck => __('Duck'),
self::turkey => __('Turkey'),
self::soupchicken => __('Soupchicken'),
self::guineafowl => __('Guineafowl'),
self::goose => __('Goose'),
};
}
public static function getImage(self $value): string {
return match ($value) {
self::chicken => "chicken.png",
self::duck => "duck.png",
self::turkey => "turkey.png",
self::soupchicken => "soupchicken.png",
self::guineafowl => "guineafowl.png",
self::goose => "goose.png",
};
}
public static function getLabels(): array {
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"label" => $value->label(),
"image" => $value->image()
]]);
}
return $arrayEnum;
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace App\Enums\Recipes;
enum CookingEnum : int {
case cook = 1;
case grill = 2;
public function label(): string {
return static::getLabel($this);
}
public function image(): string {
return static::getImage($this);
}
public static function getLabel(self $value): string {
return match ($value) {
self::cook => __('Cook'),
self::grill => __('Grill'),
};
}
public static function getImage(self $value): string {
return match ($value) {
self::cook => "cook.png",
self::grill => "grill.png",
};
}
public static function getLabels(): array {
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"label" => $value->label(),
"image" => $value->image()
]]);
}
return $arrayEnum;
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Enums\Recipes;
enum DifficultyEnum : int {
case easy = 1;
case medium = 2;
case hard = 3;
public function label(): string {
return static::getLabel($this);
}
public static function getLabel(self $value): string {
return match ($value) {
self::easy => __('Easy'),
self::medium => __('Medium'),
self::hard => __('Hard'),
};
}
public static function getLabels(): array {
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"label" => $value->label()
]]);
}
return $arrayEnum;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace App\Enums\Sliders;
enum TypeEnum : int {
case home = 1;
public function label(): string {
return static::getLabel($this);
}
public static function getLabel(self $value): string {
return match ($value) {
self::home => __('Homepage'),
};
}
public static function getLabels(): array {
$arrayEnum = [];
foreach (self::cases() as $key => $value) {
$arrayEnum = array_merge($arrayEnum, [[
"value" => $value->value,
"label" => $value->label()
]]);
}
return $arrayEnum;
}
}

View file

@ -1,65 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
class User extends Authenticatable
{
use HasFactory;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'firstname',
'lastname',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
// * EVENT CLOSURES.
static::creating(function (User $user) {
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
static::updating(function (User $user) {
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
}
}

View file

@ -1,41 +0,0 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'firstname' => $this->faker->firstname(),
'lastname' => $this->faker->lastname(),
'email' => $this->faker->unique()->safeEmail(),
'email_verified_at' => now(),
// * password
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function unverified()
{
return $this->state(function () {
return [
'email_verified_at' => null,
];
});
}
}