You see, I have to create a pdf with the curriculum of a person. They have to put that person's data, training courses and languages and their work experience.
User:
Schema::create('users', function(Blueprint $table){
$table->increments('id');
$table->string('name');
$table->string('second_name')->nullable();
$table->string('provincia')->nullable();
$table->string('localidad')->nullable();
$table->string('direccion')->nullable();
$table->string('telefono');
$table->string('dni');
$table->boolean('vehiculo')->default(false);
$table->string('foto')->default('anonimo.jpg');
$table->boolean('activado')->default(false); // Se marca aqui como falso y ya se pone automaticamente así al hacer el formulario.
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Training courses:
Schema::create('formacions', function (Blueprint $table) {
$table->increments('id');
$table->string('titulo');
$table->string('grado');
$table->string('centro');
$table->boolean('finalizacion');
$table->unsignedInteger('anyio_finalizacion')->nullable();
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
Language courses:
Schema::create('idiomas', function (Blueprint $table) {
$table->increments('id');
$table->string('idioma');
$table->string('nivel_hablado');
$table->string('nivel_escrito');
$table->string('titulo_oficial');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
$table->index(['user_id', 'idioma']);
});
Work experience:
Schema::create('experiencias', function (Blueprint $table) {
$table->increments('id');
$table->string('puesto');
$table->string('funcion_realizada');
$table->string('empresa');
$table->string('sector_empresa');
$table->string('mes_anyo_inicio');
$table->string('mes_anyo_fin');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
All this is handled with the following function:
public function exportar(User $usuario){
$formaciones=$usuario->formacion;
$idiomas=$usuario->idiomas;
$experiencias=$usuario->experiencias;
$pdf = PDF::loadView('pdf.curriculo', compact('usuario','idiomas','formaciones','experiencias'));
return $pdf->download('Curriculo de '.$usuario->name.' '.$usuario->second_name.".pdf");
}
And the curriculum is generated in this view:
@extends('layouts.app')
<html lang="es">
<body>
<font size="17" style="display: inline;">Datos del usuario</font> <img style="width: 60px; height: 60px;" align="right" src="{{url($usuario->ruta())}}"/>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Nombre</th>
<th>Residencia</th>
<th>Telefono</th>
<th>DNI</th>
<th>Vehiculo</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $usuario->name }} {{ $usuario->second_name }}</td>
<td>{{ $usuario->direccion }} ({{ $usuario->localidad }}, {{ $usuario->provincia }})</td>
<td>{{ $usuario->telefono }}</td>
<td>{{ $usuario->dni }}</td>
<td>
@if($usuario->vehiculo)
Es poseedor de vehiculo propio
@else
No posee vehiculo propio
@endif
</td>
</tr>
</tbody>
</table>
<?php
$forma=count($formaciones);
$exp=count($experiencias);
$idi=count($idiomas);
?>
@if($forma>0)
<h3>Cursos realizados</h3>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Titulo</th>
<th>Grado</th>
<th>Centro</th>
<th>Finalización</th>
</tr>
</thead>
@forelse($formaciones as $formacion)
<tbody>
<tr>
<td>$formacion->titulo</td>
<td>$formacion->grado</td>
<td>$formacion->centro</td>
<td>
@if($formacion->finalizacion)
$formacion->anyio_finalizacion
@else
No
@endif
</td>
</tr>
</tbody>
@endforelse
</table>
@else
<h3>No ha hecho ningun curso formativo</h3>
@endif
@if($exp>0)
<h3>Idiomas estudiados</h3>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Idioma</th>
<th>Nivel de habla</th>
<th>Nivel de escritura</th>
<th>Titulo oficial</th>
</tr>
</thead>
@forelse($idiomas as $idioma)
<tbody>
<td>$idioma->idioma</td>
<td>$idioma->nivel_hablado</td>
<td>$idioma->nivel_escrito</td>
<td>$idioma->titulo_oficial</td>
</tbody>
@endforelse
</table>
@else
<h3>No ha estudiado ningun idioma</h3>
@endif
@if($idi>0)
<h3>Experiencia Laboral</h3>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Puesto</th>
<th>Función realizada</th>
<th>Empresa</th>
<th>Sector</th>
<th>Fecha de inicio</th>
<th>Fecha de finalización</th>
</tr>
</thead>
@forelse($experiencias as $experiencia)
<tbody>
<tr>
<td>$experiencia->puesto</td>
<td>$experiencia->funcion_realizada</td>
<td>$experiencia->empresa</td>
<td>$experiencia->sector_empresa</td>
<td>$experiencia->mes_anyo_inicio</td>
<td>$experiencia->mes_anyo_fin</td>
</tr>
</tbody>
@endforelse
</table>
@else
<h3>No tiene experiencia laboral</h3>
@endif
</body>
</html>
But when I execute it, I run into this:
The funny thing is that I see that line and I do not see an @endif, but a @endforelse.