Skip to main content

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 has two resource controllers: EstudianteController and CarreraController. Both extend the base Controller class located at app/Http/Controllers/Controller.php, which in turn extends Laravel’s Illuminate\Routing\Controller and includes the AuthorizesRequests, DispatchesJobs, and ValidatesRequests traits. Each controller implements all seven standard Laravel resourceful actions: index, create, store, show, edit, update, and destroy.

Route Registration

Both controllers are registered together using Route::resources() in routes/web.php, which generates a full set of named routes for each resource:
Route::get('/', function () {
    return view('welcome');
})->name('home');

Route::resources([
    'estudiantes' => 'EstudianteController',
    'carreras'    => 'CarreraController'
]);
This single declaration produces fourteen named routes — seven per resource — covering all CRUD operations for both students and programs.

EstudianteController

Located at app/Http/Controllers/EstudianteController.php, this controller manages the full lifecycle of student records. It imports all seven models at the top of the file to support the create and edit forms that require full lookup-table data.

index()

Fetches every student record from the database and passes the collection to the listing view.
public function index()
{
    $estudiantes = Estudiante::all();

    return view('estudiantes.index', compact('estudiantes'));
}
  • Route: GET /estudiantes
  • View: resources/views/estudiantes/index.blade.php
  • Data: Full $estudiantes collection

create()

Loads all six lookup model collections so the creation form can populate every dropdown (gender, program, status, country, state, city).
public function create()
{
    $sexos    = Sexo::all();
    $carreras = Carrera::all();
    $statuses = Status::all();
    $paises   = Pais::all();
    $estados  = Estado::all();
    $ciudades = Ciudad::all();

    return view('estudiantes.create', compact(
        'sexos', 'carreras', 'statuses', 'paises', 'estados', 'ciudades'
    ));
}
  • Route: GET /estudiantes/create
  • View: resources/views/estudiantes/create.blade.php

store(Request $request)

Validates all incoming form data, constructs a new Estudiante instance, persists it, and redirects to the index with a success flash message. Validation rules:
$request->validate([
    'nombres'            => 'required|max:100',
    'apellidos'          => 'required|max:100',
    'sexo'               => 'required',
    'fecha_de_nacimiento'=> 'required',
    'email'              => 'required|max:100',
    'carrera'            => 'required',
    'status'             => 'required',
    'pais'               => 'required',
    'estado'             => 'required',
    'ciudad'             => 'required',
]);
After validation passes, the controller maps each form field to its corresponding model column (e.g. the sexo field → sexo_id foreign key), saves the record, and issues a redirect:
return redirect('/estudiantes')->with('success', 'Estudiante creado con exito!');
  • Route: POST /estudiantes

show($id)

Retrieves a single student by primary key and returns the detail view.
public function show($id)
{
    $estudiante = Estudiante::find($id);

    return view('estudiantes.show', compact('estudiante'));
}
  • Route: GET /estudiantes/{id}
  • View: resources/views/estudiantes/show.blade.php

edit($id)

Loads the target student plus all six lookup collections so the edit form is pre-populated and all dropdowns are available.
public function edit($id)
{
    $estudiante = Estudiante::find($id);
    $sexos      = Sexo::all();
    $carreras   = Carrera::all();
    $statuses   = Status::all();
    $paises     = Pais::all();
    $estados    = Estado::all();
    $ciudades   = Ciudad::all();

    return view('estudiantes.edit', compact(
        'estudiante', 'sexos', 'carreras', 'statuses', 'paises', 'estados', 'ciudades'
    ));
}
  • Route: GET /estudiantes/{id}/edit
  • View: resources/views/estudiantes/edit.blade.php

update(Request $request, $id)

Applies the same validation rules as store(), then finds the existing student, assigns each field individually on the model instance, and saves.
$estudiante = Estudiante::find($id);
$estudiante->nombres             = $request->get('nombres');
$estudiante->apellidos           = $request->get('apellidos');
$estudiante->sexo_id             = $request->get('sexo');
$estudiante->fecha_de_nacimiento = $request->get('fecha_de_nacimiento');
$estudiante->email               = $request->get('email');
$estudiante->carrera_id          = $request->get('carrera');
$estudiante->status_id           = $request->get('status');
$estudiante->pais_id             = $request->get('pais');
$estudiante->estado_id           = $request->get('estado');
$estudiante->ciudad_id           = $request->get('ciudad');

$estudiante->save();

return redirect('/estudiantes')->with('success', 'Estudiante actualizado con exito!');
  • Route: PUT/PATCH /estudiantes/{id}

destroy($id)

Finds the student by ID, deletes the record, and redirects to the index with a confirmation message.
public function destroy($id)
{
    $estudiante = Estudiante::find($id);
    $estudiante->delete();

    return redirect('/estudiantes')->with('success', 'Estudiante eliminado exitosamente!');
}
  • Route: DELETE /estudiantes/{id}

CarreraController

Located at app/Http/Controllers/CarreraController.php, this controller manages academic programs. It is simpler than EstudianteController because a Carrera only has one relationship (to Status) and three fillable fields.

index()

Retrieves all programs and returns the listing view.
public function index()
{
    $carreras = Carrera::all();

    return view('carreras.index', compact('carreras'));
}
  • Route: GET /carreras
  • View: resources/views/carreras/index.blade.php

create()

Loads all statuses for the dropdown on the creation form.
public function create()
{
    $statuses = Status::all();

    return view('carreras.create', compact('statuses'));
}
  • Route: GET /carreras/create
  • View: resources/views/carreras/create.blade.php

store(Request $request)

Validates the three required fields, creates a new Carrera, saves it, and redirects. Validation rules:
$request->validate([
    'nombre'     => 'required|max:100',
    'descripcion'=> 'required|max:180',
    'status'     => 'required',
]);
The controller then constructs and saves the model:
$carrera = new Carrera([
    'nombre'      => $request->get('nombre'),
    'descripcion' => $request->get('descripcion'),
    'status_id'   => $request->get('status'),
]);

$carrera->save();

return redirect('/carreras')->with('success', 'Carrera creada con exito!');
  • Route: POST /carreras

show($id)

Finds a program by ID and renders the detail view.
public function show($id)
{
    $carrera = Carrera::find($id);

    return view('carreras.show', compact('carrera'));
}
  • Route: GET /carreras/{id}
  • View: resources/views/carreras/show.blade.php

edit($id)

Retrieves the target program and all statuses for the edit form.
public function edit($id)
{
    $carrera  = Carrera::find($id);
    $statuses = Status::all();

    return view('carreras.edit', compact('carrera', 'statuses'));
}
  • Route: GET /carreras/{id}/edit
  • View: resources/views/carreras/edit.blade.php

update(Request $request, $id)

Validates, locates the program, assigns each field directly, and saves.
$carrera = Carrera::find($id);
$carrera->nombre      = $request->get('nombre');
$carrera->descripcion = $request->get('descripcion');
$carrera->status_id   = $request->get('status');

$carrera->save();

return redirect('/carreras')->with('success', 'Carrera actualizada con exito!');
  • Route: PUT/PATCH /carreras/{id}

destroy($id)

Deletes a program by ID and redirects with a confirmation message.
public function destroy($id)
{
    $carrera = Carrera::find($id);
    $carrera->delete();

    return redirect('/carreras')->with('success', 'Carrera eliminada exitosamente!');
}
  • Route: DELETE /carreras/{id}

Flash Messages

Both controllers use Laravel’s session flash pattern to communicate the outcome of write operations to the user. After a successful store, update, or destroy, the controller chains ->with('key', 'message') onto the redirect response:
// Student created
return redirect('/estudiantes')->with('success', 'Estudiante creado con exito!');

// Student updated
return redirect('/estudiantes')->with('success', 'Estudiante actualizado con exito!');

// Student deleted
return redirect('/estudiantes')->with('success', 'Estudiante eliminado exitosamente!');

// Program created
return redirect('/carreras')->with('success', 'Carrera creada con exito!');

// Program updated
return redirect('/carreras')->with('success', 'Carrera actualizada con exito!');

// Program deleted
return redirect('/carreras')->with('success', 'Carrera eliminada exitosamente!');
The index views check for the flash key using session()->get('success') and render it inside a Bootstrap alert:
@if(session()->get('success'))
  <div class="alert alert-success">
    {{ session()->get('success') }}
  </div>
@endif
This pattern provides immediate feedback without persisting a notification in the database. The message is available for exactly one subsequent request and then discarded automatically by Laravel’s session middleware.
Validation errors are handled separately by Laravel’s ValidatesRequests trait (inherited through the base Controller). When validation fails, the framework automatically redirects back to the form and populates the $errors bag, which the views display using @if ($errors->any()).

Build docs developers (and LLMs) love