Script erstellt

This commit is contained in:
Housemann
2025-08-10 18:09:07 +02:00
commit 2a15995cbb
196 changed files with 24790 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Manufacturer extends Model
{
use HasFactory;
/**
* Die Tabelle, die dem Model zugeordnet ist.
*/
protected $table = 'manufacturers';
protected $fillable = [
'name',
'description',
'website',
'country',
];
/**
* Beziehung zu Nagellacken
*/
public function nailPolishes()
{
return $this->hasMany(NailPolish::class);
}
/**
* Scope für Suche nach Name
*/
public function scopeSearch($query, $search)
{
return $query->where('name', 'like', "%{$search}%")
->orWhere('description', 'like', "%{$search}%")
->orWhere('country', 'like', "%{$search}%");
}
/**
* Gibt den Namen des Herstellers zurück
*/
public function getDisplayNameAttribute()
{
return $this->name;
}
/**
* Prüft, ob der Hersteller Nagellacke hat
*/
public function hasNailPolishes()
{
return $this->nailPolishes()->exists();
}
/**
* Anzahl der Nagellacke dieses Herstellers
*/
public function getNailPolishCountAttribute()
{
return $this->nailPolishes()->count();
}
}

48
app/Models/NailPolish.php Executable file
View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NailPolish extends Model
{
use HasFactory;
/**
* Die Tabelle, die dem Model zugeordnet ist.
*/
protected $table = 'nail_polishes';
protected $fillable = [
'name',
'number',
'manufacturer_id',
'image_path',
];
/**
* Beziehung zu Benutzern
*/
public function users()
{
return $this->belongsToMany(User::class, 'user_nail_polishes', 'nail_polish_id', 'user_id');
}
/**
* Beziehung zum Hersteller
*/
public function manufacturer()
{
return $this->belongsTo(Manufacturer::class);
}
/**
* Scope für Suche nach Name oder Nummer
*/
public function scopeSearch($query, $search)
{
return $query->where('name', 'like', "%{$search}%")
->orWhere('number', 'like', "%{$search}%");
}
}

83
app/Models/User.php Executable file
View File

@@ -0,0 +1,83 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'is_admin',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
/**
* Beziehung zu Nagellacken
*/
public function nailPolishes()
{
return $this->belongsToMany(NailPolish::class, 'user_nail_polishes', 'user_id', 'nail_polish_id');
}
/**
* Prüft, ob der User ein Admin ist
*/
public function isAdmin()
{
return $this->is_admin || in_array($this->email, ['admin@neonail.com', 'neueradmin@neonail.com']);
}
/**
* Macht den User zum Admin
*/
public function makeAdmin()
{
$this->is_admin = true;
$this->save();
}
/**
* Entfernt Admin-Rechte
*/
public function removeAdmin()
{
$this->is_admin = false;
$this->save();
}
}