gpt4 book ai didi

php - 如何修复 undefined variable : collaborators in domPDF in Laravel

转载 作者:行者123 更新时间:2023-11-29 11:08:15 25 4
gpt4 key购买 nike

我将使用 domPDF 打印 PDF。这是我的CollaboPDFController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use PDF;
use App\Collaboration;

class CollaboPDFController extends Controller
{
public function getPDF(){
$collaborators = Collaboration::all();
$pdf = PDF::loadView('collaborators.form',['Collaborators'=>$collaborators]);
return $pdf->stream('form.collaborators');
}
//
}

这是我的 Blade View 女巫,我将打印为 pdf 文件。它是 collaborators 文件夹中的 form.blade.php 文件。

<div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;">
<h4 class="page-header">
Collaborators
</h4>
@if($collaborators)
@foreach( $collaborators as $collaborator)
<div>
<div>
<span>
<img src="{{ $collaborator->user()->first()->getAvatarUrl() }}" />
{{ $collaborator->user()->first()->username}}
{{ $collaborator->user()->first()->id}}

</span>
</div>

最佳答案

据我所知,变量是区分大小写的,尝试替换['协作者'=>$协作者]['collaborators'=>$collaborators]

关于php - 如何修复 undefined variable : collaborators in domPDF in Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com