Documentation Index
Fetch the complete documentation index at: https://mintlify.com/keving5726/megacreative/llms.txt
Use this file to discover all available pages before exploring further.
Mega Creative uses seven Eloquent models in the App\ namespace, all located in the app/ directory. The Estudiante model is the central entity: it stores every student record and holds relationships pointing to all six supporting models. Understanding these models and how they relate to each other is the foundation for working with any feature of the application.
Estudiante
Estudiante maps to the estudiantes database table and represents a registered student. It uses $guarded to protect only the auto-managed timestamp and primary-key columns, leaving all other fields mass-assignable.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Estudiante extends Model
{
protected $table = 'estudiantes';
protected $guarded = ['id, created_at, updated_at'];
// Relaciones
public function sexo()
{
return $this->hasOne('App\Sexo', 'id', 'sexo_id');
}
public function carrera()
{
return $this->hasOne('App\Carrera', 'id', 'carrera_id');
}
public function status()
{
return $this->hasOne('App\Status', 'id', 'status_id');
}
public function pais()
{
return $this->hasOne('App\Pais', 'id', 'pais_id');
}
public function estado()
{
return $this->hasOne('App\Estado', 'id', 'estado_id');
}
public function ciudad()
{
return $this->hasOne('App\Ciudad', 'id', 'ciudad_id');
}
}
Key Properties
| Property | Value | Notes |
|---|
$table | 'estudiantes' | Explicit table name |
$guarded | ['id, created_at, updated_at'] | All other columns are mass-assignable |
| Timestamps | Enabled (default) | created_at and updated_at are managed automatically |
Relationships
All six relationships are defined as hasOne() associations using a foreign key on the estudiantes table and the primary key (id) on each related table.
| Method | Related Model | Foreign Key on estudiantes |
|---|
sexo() | App\Sexo | sexo_id |
carrera() | App\Carrera | carrera_id |
status() | App\Status | status_id |
pais() | App\Pais | pais_id |
estado() | App\Estado | estado_id |
ciudad() | App\Ciudad | ciudad_id |
Carrera
Carrera maps to the carreras table and represents an academic degree program. Unlike Estudiante, it uses an explicit $fillable array instead of $guarded, and timestamps are disabled.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Carrera extends Model
{
protected $table = 'carreras';
protected $fillable = ['nombre', 'descripcion', 'status_id'];
public $timestamps = false;
// Relaciones
public function status()
{
return $this->hasOne('App\Status', 'id', 'status_id');
}
}
Key Properties
| Property | Value | Notes |
|---|
$table | 'carreras' | Explicit table name |
$fillable | ['nombre', 'descripcion', 'status_id'] | Only these three fields may be mass-assigned |
$timestamps | false | created_at / updated_at columns are not used |
Relationships
| Method | Related Model | Foreign Key on carreras |
|---|
status() | App\Status | status_id |
Lookup Models
The five remaining models serve as reference tables that provide dropdown data for student and program forms. They share a common profile: no timestamps, no explicit fillable/guarded declarations (beyond the default), and no relationships of their own.
| Model | Table | Timestamps | Primary Use |
|---|
Sexo | sexos | false | Gender options displayed in the student form ($sexo->tipo) |
Status | statuses | false | Active/inactive status shared by both students and programs ($status->status) |
Pais | paises | false | Country selection for a student’s location ($pais->nombre) |
Estado | estados | false | State or province within a country ($estado->nombre) |
Ciudad | ciudades | false | City within a state ($ciudad->nombre) |
Because none of the lookup models declare $fillable or $guarded, mass-assignment protection falls back to Eloquent’s default behaviour. They are primarily read from (via ::all() in controllers) rather than written to through user-facing forms.
Working with Relationships
Below are practical Eloquent examples demonstrating how to access related data through the Estudiante and Carrera models.
// Find a student by primary key
$estudiante = Estudiante::find(1);
// Access the student's program name via the carrera() relationship
echo $estudiante->carrera->nombre;
// Access the student's gender label
echo $estudiante->sexo->tipo;
// Access the student's enrollment status
echo $estudiante->status->status;
// Access the student's full location chain
echo $estudiante->pais->nombre; // e.g. "Venezuela"
echo $estudiante->estado->nombre; // e.g. "Miranda"
echo $estudiante->ciudad->nombre; // e.g. "Caracas"
// Retrieve all students
$estudiantes = Estudiante::all();
// Retrieve all programs, eager-loading their status to avoid N+1 queries
$carreras = Carrera::with('status')->get();
foreach ($carreras as $carrera) {
echo $carrera->nombre . ' — ' . $carrera->status->status;
}
Estudiante uses $guarded while Carrera uses $fillable. Both approaches protect against unintended mass assignment, but they work in opposite directions: $guarded lists the columns that cannot be set in bulk, while $fillable lists the columns that can be. For Estudiante, all student-facing columns (nombres, apellidos, email, etc.) are automatically mass-assignable because only the primary key and timestamps are guarded. For Carrera, only nombre, descripcion, and status_id are permitted.
The hasOne() relationships on Estudiante assume every foreign-key column (sexo_id, carrera_id, etc.) holds a valid ID that exists in the related table. If any lookup table is empty or a student record holds a stale ID, accessing the relationship will return null and trigger a "Trying to get property of non-object" error. Ensure seeders are run before creating student records in development.