0

I have two data and I will make one data for each pdf. but the output that I produce is one pdf and only the first loop data is displayed. is there something wrong? thank you

public function emailPdf(Request $request){

        DB::beginTransaction();
        // $autocrm_class = new CRM;

        $post = $request->all();

        $post['id_brand'] = 1;
        $post['date_today'] = "2020-02-07";

        // $post['date_today'] = date('Y-m-d', strtotime($post['date_today']));

        $data = BrandOutlet::where('id_brand', $post['id_brand'])->with('brandOutletDelivery.brandOutletTujuan');
        $data->with(["brandOutletDelivery.brandOutletDeliveryItems" => function($q) use($post){
            $q->whereDate('created_at', '=', $post['date_today'])->with('brandItem')->with('unit');
        }]);

        $data->with(["brandOutletOpnamePagi.brandOutletOpnameItems" => function($q) use($post){
            $q->whereDate('created_at', [$post['date_today']])->with('brandItem')->with('unit');

        }]);

        $data->with(["brandOutletOpnameMalam.brandOutletOpnameItems" => function($q) use($post){
            $q->whereDate('created_at', [$post['date_today']])->with('brandItem')->with('unit');

        }]);


        $data = $data->get();

            $html = '';
            foreach($data as $result){
                $view = view('pdf.delivery', ['result' => $result]);
                $html .= $view->render();
            }

            // return $html //I tried to debug by displaying it in View and the result is 2 data
            $pdf = \PDF::loadHtml($html);
            $sheet = $pdf->setPaper('a4', 'landscape');
            $pdf->save('pdf/'.$result['id'].'.pdf');
            return $sheet->stream();
        }

1 Answer 1

1
    $html = [];
        foreach($data as $i=>$result){
            $view = view('pdf.delivery', ['result' => $result]);
            $html[$i]= $view->render();
        }



foreach($html as $htm){
        $pdf = \PDF::loadHtml($htm);
        $sheet = $pdf->setPaper('a4', 'landscape');
        $pdf->save('pdf/'.$result['id'].'.pdf');
        return $sheet->stream();

}

please try this

Sign up to request clarification or add additional context in comments.

9 Comments

Does not have any effect, just changes to the loop to other data
and also data in PDF blank (only header in PDF is displayed)
sorry i miss understand u
solve it by this code foreach($data as $i=>$result){ $view = view('pdf.delivery', ['result' => $result]); $html[$i] = $view->render(); }
I have tried the method above. but there isn't any effect. Sorry if my language can't be understood
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.