proyectos:registro_comidas
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| proyectos:registro_comidas [2025/03/30 17:19] – [Comidas] tempwin | proyectos:registro_comidas [2025/03/30 18:54] (actual) – [Migración] tempwin | ||
|---|---|---|---|
| Línea 13: | Línea 13: | ||
| ===== Estructura de base de datos ===== | ===== Estructura de base de datos ===== | ||
| + | |||
| + | ==== Tipos de comida ==== | ||
| + | |||
| + | * id | ||
| + | * nombre | ||
| + | * slug | ||
| + | * descripción | ||
| ==== Comidas ==== | ==== Comidas ==== | ||
| Línea 72: | Línea 79: | ||
| </ | </ | ||
| + | ===== Tipos de comida ===== | ||
| + | |||
| + | Según el momento del día: | ||
| + | |||
| + | * Desayuno | ||
| + | * Comida | ||
| + | * Cena | ||
| + | * Tentempié / picoteo / snack | ||
| + | |||
| + | ==== Migración ==== | ||
| + | |||
| + | < | ||
| + | php artisan make: | ||
| + | </ | ||
| + | |||
| + | Contenido del fichero '' | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | |||
| + | use Illuminate\Database\Migrations\Migration; | ||
| + | use Illuminate\Database\Schema\Blueprint; | ||
| + | use Illuminate\Support\Facades\Schema; | ||
| + | |||
| + | return new class extends Migration | ||
| + | { | ||
| + | /** | ||
| + | * Run the migrations. | ||
| + | */ | ||
| + | public function up(): void | ||
| + | { | ||
| + | Schema:: | ||
| + | $table-> | ||
| + | $table-> | ||
| + | $table-> | ||
| + | $table-> | ||
| + | $table-> | ||
| + | }); | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Reverse the migrations. | ||
| + | */ | ||
| + | public function down(): void | ||
| + | { | ||
| + | Schema:: | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Modelo ==== | ||
| + | |||
| + | Lo creamos con: | ||
| + | |||
| + | < | ||
| + | php artisan make:model MealType | ||
| + | </ | ||
| + | |||
| + | Contenido del fichero generado '' | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | |||
| + | namespace App\Models; | ||
| + | |||
| + | use Illuminate\Database\Eloquent\Model; | ||
| + | |||
| + | class MealType extends Model | ||
| + | { | ||
| + | // | ||
| + | } | ||
| + | |||
| + | </ | ||
| ===== Categorías ===== | ===== Categorías ===== | ||
| Línea 252: | Línea 333: | ||
| <code php> | <code php> | ||
| <?php | <?php | ||
| - | + | ||
| namespace App\Models; | namespace App\Models; | ||
| - | + | ||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
| - | + | use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
| - | + | use Illuminate\Database\Eloquent\Relations\BelongsToMany; | |
| - | class Category | + | |
| + | class Meal extends Model | ||
| { | { | ||
| use HasFactory; | use HasFactory; | ||
| - | + | ||
| - | protected $fillable = [' | + | protected $fillable = [ |
| - | + | | |
| - | public function | + | |
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | | ||
| + | |||
| + | protected $casts = [ | ||
| + | ' | ||
| + | ]; | ||
| + | |||
| + | // Relaciones | ||
| + | public function | ||
| { | { | ||
| - | return $this->hasMany(Meal::class); | + | return $this->belongsTo(User::class); |
| } | } | ||
| - | + | ||
| - | public function | + | public function |
| { | { | ||
| - | return $this->hasMany(Ingredient:: | + | return $this->belongsTo(Category:: |
| + | } | ||
| + | |||
| + | public function ingredients(): | ||
| + | { | ||
| + | return $this-> | ||
| + | -> | ||
| + | -> | ||
| + | } | ||
| + | |||
| + | public function tags(): BelongsToMany | ||
| + | { | ||
| + | return $this-> | ||
| + | -> | ||
| + | } | ||
| + | |||
| + | // Accesor para el lugar | ||
| + | public function getLocationAttribute(): | ||
| + | { | ||
| + | return match($this-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | default => ' | ||
| + | }; | ||
| } | } | ||
| } | } | ||
proyectos/registro_comidas.1743347959.txt.gz · Última modificación: por tempwin
