如何在dompdf laravel中显示数据库中的个人资料图片

时间:2018-08-07 02:43:57

标签: laravel dompdf

我想在通过dompdf生成PDF的结果中显示数据库中的个人资料图片,但是结果是Image not found or type unknown

我的控制器

public function generatePDF(Request $request)
{ 
  $id = Auth::user()->id;
  $user = array(
         "photo_url" =>  User::select("PHOTO_URL")->where("id", $id)->get()
        )
  $data["user"] = $user;

  $pdf = PDF::loadView('generatePDF', $data);
  return $pdf->stream('generatePDF.pdf');   

我的观点

<img src="{{ asset('storage/imgprofile') . '/' . $user['photo_url'][0]['PHOTO_URL'] }}" width="220" height="220" alt="Profile Picture" /> 

1 个答案:

答案 0 :(得分:0)

在您的控制器中:

User::select("PHOTO_URL")->where("id", $id)->get()

替换为:

User::find($id, ['PHOTO_URL'];

您认为:

<img src="{{ asset('storage/imgprofile') . '/' . $user->PHOTO_URL }}" width="220" height="220" alt="Profile Picture" />