当我尝试将数据转换为PDF时,我得到错误:在pdfview.blade.php中取消确定变量$ incomes

时间:2017-02-18 08:40:02

标签: php pdf

这是我的pdfview.blad.php

<div class="container">
<br/>
<a href="{{ route('pdfview',['download'=>'pdf'])}}">Download PDF</a>

<table>
    <tr>
        <th>No</th>
        <th>Income name</th>
        <th>Amount</th>
        <th>Description</th>
        <th>Date</th>
    </tr>
     @foreach ($incomes as $key => $income)
    <tr>
        <td>{{ ++$key }}</td>
        <td>{{ $income->income_name }}</td>
        <td>{{ $income->income_amount }}</td>
        <td>{{ $income->income_des }}</td>
        <td>{{ $income->income_date }}</td>
    </tr>
     @endforeach
</table>
</div

> Blockquote

这是我的pdfcontroller,我在其中编写下载PDF链接的代码和PDF格式的转换文件的编码

<?php
namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use DB;
use PDF;

class pdfcontroller extends Controller
{

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function pdfview(Request $request)
{
    $incomes = \DB::table("income")->get();
    view()->share('income',$incomes);

    if($request->has('download'))
    {
        $pdf = PDF::loadView('pdfview');

        return $pdf->download('pdfview.pdf');
    }

    return view('pdfview')->with(compact('incomes'));
}
}

在route.php中,我编写了以下代码,        路线::得到( '/ pdfview',阵列( '作为'=&GT; 'pdfview', '使用'=&GT; 'pdfcontroller @ pdfview');

0 个答案:

没有答案