skip to Main Content

Is there a way to make it such that when we call php artisan make:export, the default export file generated implements FromView and not FromCollection?

2

Answers


  1. if you need collection you need to import its :

    use MaatwebsiteExcelConcernsWithMapping;
    

    and

    class EntityExport implements WithMapping
    

    and using like thats :

    public function map($row): array
    {
        return [
            $row->id,
            $row->title ? $row->title : '-',
            $row->name ? $row->name : '-',
        ];
    }
    
    Login or Signup to reply.
  2. Yes, we can do that by editing stubs. You can follow these steps:

    1. Run php artisan vendor:publish --provider="MaatwebsiteExcelExcelServiceProvider" to publish assets.

    2. Open stubs/export.plain.stub file and replace the following code.

    <?php
    
    namespace DummyNamespace;
    
    use MaatwebsiteExcelConcernsFromView;
    use IlluminateContractsViewView;
    
    class DummyClass implements FromView
    {
        /**
        * @return IlluminateContractsViewView
        */
        public function view(): View
        {
            //
        }
    }
    
    1. Now try again with php artisan make:export
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search