Call to protected method Barryvdh \ DomPDF \ PDF :: render () from context 'App \ Http \ Controllers \ UserController'

0

You see, I am creating a function which will generate the PDF with the curriculum of several users.

For this, I have this function.

public function fichaje(Sector $sector){
    $usuarios=User::whereHas('experiencias',function($query) use ($sector){
        $query->where('sector_empresa',$sector->nombre);
    })->get();

    if(count($usuarios)==0)
        return back()->with('message',['danger','No hay ningun usuario interesado en este sector']);
    else{
        foreach($usuarios as $usuario){
            $pdf = PDF::loadView('pdf.curriculo', compact('usuario'));
            $pdf->render();
            $salida=$pdf->output();
            $ruta='C:/xampp/htdocs/bolsa/public/descargas/'.'Curriculos del sector '.$sector->nombre.'.pdf';
            file_put_contents($ruta, $salida);
        }
    }
}

Which brings me to the next view:

@extends('layouts.app')
<html lang="es">
<body>
    <?php
    $formaciones=$usuario->formacion;
    $idiomas=$usuario->idiomas;
    $experiencias=$usuario->experiencias;
?>

<font size="15" style="display: inline;">Datos del usuario</font> <img style="width: 50px; height: 50px;" 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)
        <h4>Cursos realizados</h4>
        <table class="table table-hover table-striped">
            <thead>
                <tr>
                    <th>Titulo</th>
                    <th>Grado</th>
                    <th>Centro</th>
                    <th>Finalización</th>
                </tr>
            </thead>
            @foreach($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>
            @endforeach
        </table>
    @else
        <h4>No ha hecho ningun curso formativo</h4>
    @endif

    @if($idi>0)
        <h4>Idiomas estudiados</h4>
            <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>
            @foreach($idiomas as $idioma)
                <tbody>
                    <tr>
                        <td>{{$idioma->idioma}}</td>
                        <td>{{$idioma->nivel_hablado}}</td>
                        <td>{{$idioma->nivel_escrito}}</td>
                        <td>{{$idioma->titulo_oficial}}</td>
                    </tr>
                </tbody>
            @endforeach
        </table>
    @else
        <h4>No ha estudiado ningun idioma</h4>
    @endif

    @if($exp>0)
        <h4>Experiencia Laboral</h4>
        <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>
        @foreach($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>
        @endforeach
        </table>
    @else
        <h4>No tiene experiencia laboral</h4>
    @endif
</body>
</html>

This would have to be creating a PDF for each user, but I see myself to start with this error message.

How do I fix this?

    
asked by Miguel Alparez 19.05.2018 в 11:55
source

1 answer

0

It seems that I have solved it. I had to remove $pdf->render(); , which in any case was the function that caused me the protests and finally I can create multiple PDFs. Besides, I have to replace $ruta='C:/xampp/htdocs/bolsa/public/descargas/'.'Curriculos del sector '.$sector->nombre.'.pdf'; with $ruta='C:/xampp/htdocs/bolsa/public/descargas/'.'Curriculo de '.$usuario->name." ".$usuario->second_name.'.pdf'; , otherwise a unique PDF will be generated when trying to write the same PDF name several times in the same route.

    
answered by 19.05.2018 в 12:11