Sunday, January 2, 2022

[FIXED] Call to undefined method Maatwebsite\Excel\Excel::downlood() in laravel 8

Issue

I am using maatwebsite package in my laravel 8 project to download data form database as csv but i got this error when i call the downlood function from Excel from this link enter link description here

Call to undefined method Maatwebsite\Excel\Excel::downlood()

the User Controller

<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
use Illuminate\Support\Facades\Validator;


use App\Models\User;
use Carbon\Carbon;
use Excel;
use App\Exports\UserExport;

class UserController extends Controller
{
  public function ExportTOCsv(){

        return Excel::downlood(new UserExport , 'All-User.csv');
    }
}

UserExport Class

<?php

namespace App\Exports;

use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;


class UserExport implements FromCollection,WithHeadings
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return collect(User::GetAllUser());
    }

    public function headings():array{
    return[
        'Name',
        'Email',
        'Phone',
        'Membership Type',
        'Membership Status',
        'last_activation_date',
        'membership_end_date',
        'future_id',
        'temporary_id',
        'tc_no_pasaport_no',
        'place_of_birth',
        'date_of_birth',
        'educational_status',
        'school_department',
        'Institution_and_unit',
        'address',
        'referance_email',
        'letter_of_Intent',
        'created_at',
        'updated_at'
    ];

    }
}

User Model Class

<?php

namespace App\Models;

use DB;

public static function GetAllUser(){
        $result =DB::table('users')
        ->select('name',
        'email',
        'phone',
        'membership_type',
        'membership_status',
        'last_activation_date',
        'membership_end_date',
        'future_id',
        'temporary_id',
        'tc_no_pasaport_no',
        'place_of_birth',
        'date_of_birth',
        'educational_status',
        'school_department',
        'Institution_and_unit',
        'address',
        'referance_email',
        'letter_of_Intent','created_at','updated_at')
        ->get()->toArray();

        return $result;


    }


}

downlood buttom as csv

<a href="{{route('export.csv')}}" class="btn btn-rounded btn-success">Downlood All Users</a>

Route

Route::get('/export-user',[UserController::class,'ExportTOCsv'])->name('export.csv');

Solution

Looks like you typed the wrong word, it should be a download, not a downlood.

return Excel::downlood(new UserExport , 'All-User.csv');

Please change it to...

return Excel::download(new UserExport , 'All-User.csv');


Answered By - Updu

No comments:

Post a Comment

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