PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] Laravel : Too few arguments to function App\Exports\ReportExport::__construct()

 March 09, 2022     laravel, php     No comments   

Issue

My error in line 21

I have imports:

use Maatwebsite\Excel\Concerns\FromCollection;
use App\Models\EmployeeInCompany;
use Auth;
use Maatwebsite\Excel\Concerns\Exportable;

And my Export Folder : ReportExport

class ReportExport implements FromCollection
{

    use Exportable;

    protected $request;

    public function __construct($request)
    {
       $this->request = $request;
    } 

    public function collection()
    {
        if ($this->request->has('filter_date')) {
            $employee = EmployeeInCompany::where('company_id', Auth::user()->company_id)->get();
        }else{
            $employee = EmployeeInCompany::where('company_id', \Session::get('selected_company'))->get();
        }
    }

}

I made an export to excel. I use the code in the public function __construct to hold the $request variable for the date filter. how to solve my problem? help me, thanks.


Solution

2 options to handle this:

You can pass the request to your constructor in ReportController.php (make sure $request is defined):

new ReportExport($request);

or you can remove the parameter in the constructor and use the request helper function:

public function __construct()
{
   $this->request = request();
} 


Answered By - Gert B.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing