mercredi 9 septembre 2020

Export to excel using maatwebsite excel 2.0.8 and laravel 5.2 error - can't reach this page

I have this strange error in my system where exporting function using maatwebsite excel in my public function exportSales() works very successfully but when public function exportInventory is called, it doesn't works. Below is my code for both functions.

SaleController.php

this function works and downloads SalesReport.xls

public function exportSales( $param = null ){

    ob_end_clean();
    ob_start();

    $arrayMonths = ["January","February","March","April","May","June","July","August","September","October","November","December"];

    if( !$param ){

      Excel::create('SalesReport', function($excel){
      $excel->sheet('sales_sheet', function($sheet){
      $sales = Sale::orderBy('created_at','desc')->get();
      $sheet->loadView('sales/view_sales_excel', [ 'sales' => $sales ]);

      });

     })->download('xls');

    } else if( in_array( ucfirst( $param ), $arrayMonths ) ){

      Excel::create('SalesReport', function($excel) use($param){
      $excel->sheet('sales_sheet', function($sheet) use($param){
      $sales = Sale::orderBy('created_at','desc')
                         ->where('month', 'ILIKE', '%'.$param.'%')
                         ->get();
      $sheet->loadView('sales/view_sales_excel', [ 'sales' => $sales ]);

      });

     })->download('xls');                   

  }else{

    return redirect()->back()->with('message', 'Cannot export with a parameter '.$param.'. Please contact developer for additional functions needed. Thank you.');

  }

}

InventoryRecordController.php

this function doesn't work and returns can't reach this page error

public function exportInventory( $param = null ){

    ob_end_clean();
    ob_start();

    if( !$param ){

      Excel::create('InventoryReport', function($excel){

        $excel->sheet('inventory_sheet', function($sheet){

          $inventory = InventoryRecord::orderBy('created_at', 'desc')->get();
          $sheet->loadView('inventory/view_inventory_excel', [ 'inventory' => $inventory ]);

        });

      })->download('xls');

                          
    } else{

      /*$products = InventoryRecord::orderBy('pharmaceutical','asc')
                         ->where('type', 'ILIKE', '%'.$param.'%')
                         ->orwhere('unit', 'ILIKE', '%'.$param.'%')
                         ->get();*/
      return redirect()->back()->with( 'message', 'Cannot export with the parameter '.$param.'. Please contact developer for additional functions needed. Thank you.' );                   

    }

}

enter image description here enter image description here

Here are some screenshots of my code editor:

enter image description here

enter image description here

enter image description here

Please do note also that I am using xampp with 7.2.12 version, maybe this matter? Please help me figure this out. Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire