Patwan

Patwan

Member Since 2 Years Ago

Experience Points
3,150
Total
Experience

1,850 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
3,150 XP
Mar
21
2 months ago
Activity icon

Replied to Issue Generating Excel In Maatwebsite 3.1 In Laravel 6.4

@bobbybouwmann $file_name variable is passed as 1st argument but the error says argument 2 should be a string,,

This is what I have changed to

  public function export() 
    {

        $storage = public_path('documents\general\motor');
        $file_name = 'Sales_' . Carbon::now()->format('Y_m_d');
        $allData = new MotorSalesExport;

        Excel::download($file_name, function ($excel) use ($allData) {

            $excel->sheet('Motor Customers', function ($sheet) use ($allData) {
                $sheet->fromArray($allData, '', 0, false, false);
            });
        })->store('xls', $storage);
      
    }
Activity icon

Replied to Issue Generating Excel In Maatwebsite 3.1 In Laravel 6.4

@bobbybouwmann Tried to change according to your suggestion but am still getting the same error

Activity icon

Started a new Conversation Issue Generating Excel In Maatwebsite 3.1 In Laravel 6.4

Am working on a Laravel application whereby am trying to generate excel from data in 2 tables on my database. Have used SQL joins to join data from the database tables which works fine. Am trying to create an excel from te data (using Maatwebsite Laravel Excel package 3.1), then store the excel in a folder in my application, then sent the excel as an attachment of an email body.

The problem is when I run the command to generate the excel, I keep getting this error.

Symfony\Component\Debug\Exception\FatalThrowableError : Argument 2 passed to Maatwebsite\Excel\Excel::download() must be of the type string, object given, called in C:\xampp\htdocs\jub\ven dor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 261

I have followed the documentation and other solutions on the web but seems am missing out on something in my logic.

  1. Export Class from the documentation
php artisan make:export MotorSalesExport
  1. MotorSalesExport.php file
  <?php

        namespace App\Exports;

        use Modules\Motor\Entities\User;
        use Modules\Motor\Entities\Quotation;
        use Maatwebsite\Excel\Concerns\FromCollection;
        use DB;

        class MotorSalesExport implements FromCollection
        {
            /**
            * @return \Illuminate\Support\Collection
            */
            public function collection()
            {
                 //Combine data in Quotations and users table
                $allSales = DB::select('SELECT q.quotation_no, q.policy_number,  q.premium_amount,
                q.balance, q.business_type, q.risk_note, q.debit_note, q.output_status,
                u.first_name , u.middle_name, u.surname, u.email, u.phone, u.email, u.kra_pin, u.id_number
                FROM digital_lab_motor_quotations q INNER JOIN digital_lab_motor_users u ON 
                u.id=q.user_id WHERE q.payment_status = 2 AND payment_status= 2');

                return $allSales;
            }
        }
  1. Artisan Command to generate the excel
  <?php

    namespace App\Console\Commands\General;

    use DB;
    use Carbon\Carbon;
    use Illuminate\Console\Command;
    use Mail;
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use App\Exports\MotorSalesExport;
    use Maatwebsite\Excel\Facades\Excel;


    class GenerateMotorSales extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'generate-motor-sales';

        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'Queries all motor sales made online and generate an excel';

        /**
         * Create a new command instance.
         *
         * @return void
         */
        public function __construct()
        {
            parent::__construct();
        }

        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle()
        {
            $this->export();
        }


        public function export() 
        {

            $storage = public_path('documents\general\motor');
            $file_name = 'Sales_' . Carbon::now();
            $allData = new MotorSalesExport;

            Excel::download($file_name, function ($excel) use ($allData) {

                $excel->sheet('Motor Customers', function ($sheet) use ($allData) {
                    $sheet->fromArray($allData, '', 0, false, false);
                });
            })->store('xls', $storage);
        }
    }