mardi 28 février 2017

Laravel dom-pdf issue sending id value and checkboxes to pdf

Could anyone help me by explaining how to dynamicaly update data in laravel dom-pdf file?

i have an isssue with sending an id value to pdf file and dynamically representing data in pdf file using dom-pdf for laravel. I use Laravel 5.3.28

->I have a search form with wich user finds specific post address (every address have an unique id value for it)

->after that - user is sent to a page (view) where he/she can choose to click on multiple checkboxes (or dont click on any of them at all) for more options for the specific adress.

_>After this user is sent to a view where he/she can click on an pdf icon image and download the generated pdf file.

In this file there should be an information taken from database based on selected adress (selected by its id value) and if the user has chosen some of the options from the checkboxes also the text, values for that specific checkboxes. I hope you understood what im trying to do.

The problem is that i can't send the specific id values to this pdf file for dynamic content update, also the checkboxes are not working properly.

Sorry for my english.

Here is my controller file:

class ItemController extends Controller
{
    public function pdfview()
    {
    //$items = DB::table("lv_cities")->get();
    //$items = Input::get('info');
    $objid = Input::get('objid');
    $results = streetnr::where('streetnrid', "=", $objid)->get();
    return view('pdf.pdfview')->with('results',$results)->with('objid',$objid); 
    }

    public function pdfview2(Request $request,$id)
    {
    //$objid = Input::get('objid');
    //$results = streetnr::where('streetnrid', "=", $objid)->get();
    $objid = streetnr::findOrFail($id);
    $results = DB::table('lv_streetnr')->first();
    view()->share('results',$results);
    $pdf = PDF::loadView('pdf.pdfreport',['objid' => $objid]);
    return $pdf->download('report.pdf', array('Attachment'=>0));
    //$pdf = PDF::loadView('pdf.pdfreport', compact('objid','results', 'opt1html', 'opt2html', 'opt3html', 'opt4html', 'opt5html', 'opt6html', 'opt7html', 'opt8html', 'opt9html', 'opt10html', 'opt11html', 'opt12html', 'opt13html'));
    //$pdf->loadView('pdf', array('data' => 'test'));
    //return $pdf->download('propertyinfo.pdf');
    }

here is my routes

Route::get('pdfview', 'ItemController@pdfview');
Route::get('pdfview2/{id}', 'ItemController@pdfview2');

here is my pdfview view file

@extends('layouts.app')
@section('content')
 <div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
<div class="panel-body">
            @if (Auth::check())
                    You <B>are</B> logged in!<BR>
<div class="alert alert-info">
  Download report for property <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><BR>
  <a href="pdfview2/"><img src="http://ift.tt/2m919sd" style="width:10%;height:10%;">
  <BR>
    Download PDF</a>
</div>
    <BR>
            <input name="objid" type="hidden" value="">
            homename/streename id: <BR>       
                @else
                    You <B>are not</B> logged in!<BR><BR><BR>
            @endif
                </div></div></div></div></div>@endsection

here is my pdfreport view file - this is the file from wich the pdf file is generated:

<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
body {
    font: normal 10px Verdana, Arial, sans-serif;
}
.page-break {
    page-break-after: always;
}
</style>
    </head>
    <body>
<BR>
ID: {!!$objid->property!!}
@if(isset($results->streetnrid)) streetnr id: <BR> @endif
@if(isset($results->streetname)) streetname: <BR> @endif
@if(isset($results->streetnr)) streetnr: <BR> @endif
@if(isset($results->id)) DB ID: <BR> @endif
@if(isset($results->village_n)) village name: <BR> @endif
@if(isset($results->parish_n)) parish name: <BR> @endif
@if(isset($results->city_n)) city name: <BR> @endif
<div class="page-break"></div>

            @if(isset($opt1)) opt1 is checked @endif
            @if(isset($opt2)) opt2 is checked @endif
            @if(isset($opt3)) opt3 is checked @endif
            @if(isset($opt4)) opt4 is checked @endif
            @if(isset($opt5)) opt5 is checked @endif
            @if(isset($opt6)) opt6 is checked @endif
            @if(isset($opt7)) opt7 is checked @endif
            @if(isset($opt8)) opt8 is checked @endif
            @if(isset($opt9)) opt9 is checked @endif
            @if(isset($opt10)) opt10 is checked @endif
            @if(isset($opt11)) opt11 is checked @endif
            @if(isset($opt12)) opt12 is checked @endif
            @if(isset($opt13)) opt13 is checked @endif
    </body>
</html>

and here is the starting view file in which user can click on checkboxes etc.

@extends('layouts.app')
@section('content')
 <div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
            <div class="panel-body">
            @if (Auth::check())
            You <B>are</B> logged in!<BR><BR><BR>
            <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong><br>
            <strong></strong>
            <BR>
            ID: 
<BR>
<form method="get" action="pdfview">
<input name="objid" type="hidden" value="">
<b>Basic options - 3.50 EUR</b><br/>
<input type="checkbox" name="opt1" value="3.00">Options 1 - 3 EUR<br/>
<input type="checkbox" name="opt2" value="1.50">Options 2 - 1.50 EUR<br/>
<input type="checkbox" name="opt3" value="3.60">Options 3 - 3.60 EUR<br/>
<input type="checkbox" name="opt4" value="2.50">Options 4 - 2.50 EUR<br/>
<input type="checkbox" name="opt5" value="2.80">Options 5 - 2.80 EUR<br/>
<input type="checkbox" name="opt6" value="2.50">Options 6 - 2.50 EUR<br/>
<input type="checkbox" name="opt7" value="3">Options 7 - 3 EUR<br/>
<input type="checkbox" name="opt8" value="2.50">Options 8 - 2.50 EUR<br/>
<input type="checkbox" name="opt9" value="2.50">Options 9 - 2.50 EUR<br/>
<input type="checkbox" name="opt10" value="3.50">Options 10 - 3.50 EUR<br/>
<input type="checkbox" name="opt11" value="3.50">Options 11 - 3.50 EUR<br/>
<input type="checkbox" name="opt12" value="2.50">Options 12 - 2.50 EUR<br/>
<input type="checkbox" name="opt13" value="3">Options 13 - 3 EUR<br/>
<h2>Kopā: <span name="total" class="total">3.50</span> EUR</h2>
<BR><input type="submit" id="adress_submit" value="search" class="btn btn-primary">
</form>
@else
You <B>are not</B> logged in!<BR><BR><BR>
@endif
</div>
<script>
$(function() {
$('input').click(function(){
var total = 3.50;
$('input:checked').each(function(index, item) {
total += parseFloat(item.value);
});
$('.total').text(total);
});
}); 
</script>
@endsection
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire