mercredi 11 janvier 2023

Get data eloquent to Dompdf with response->json in laravel

How to get data eloquent to Dompdf with response->json in laravel. if i use,

$pdf = PDF::loadview('ipdf',['ipdf'=>$ipdf]);
return $pdf->stream();

if i dont use it, img

My controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PDF;
use App\Http\Controllers\Controller;
use App\Helpers\MessageHelper;
use App\Helpers\StockHelper;
use Illuminate\Http\JsonResponse;
use App\Helpers\StringRandomHelper;
use App\Models\Order;
use App\Models\OrderDetail;
use App\Models\Sablon;
use App\Models\Stock;
use App\Models\Customer;
use App\Models\ProductSize;
use DB;
class IpdfController extends Controller
{
    public function __construct()
    {
        $this->model = new Order;
    }

    public function index(Request $request) {
        $ipdf = Order::with('orderDetail')->paginate(15);
        return view('ipdf', ['ipdf'=>$ipdf]);
    }
    public function cetak_pdf($id)
    {
        $ipdf = $this->model->with(['orderDetail.productSize.productColor.productCategories.product'])->find($id);
        $ipdf = $ipdf->where('id', '=', $id)->orderby('created_at','desc')->get();
        return response()->json($ipdf);
        // $pdf = PDF::loadview('ipdf',['ipdf'=>$ipdf]);
        // $pdf = PDF::loadview('ipdf',compact('ipdf'));
        // return $pdf->stream();
    }
}

get/read data eloquent by id to Dompdf with response->json in laravel



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire