Search code examples
laravellaravel-5laravel-excel

Laravel 5.8 "Class 'App\Exports\Auth' not found"


I am trying to download records related to authenticated user using maatwebsite/excel and here is my export:

<?php

namespace App\Exports;

use App\User;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Maatwebsite\Excel\Concerns\FromCollection;

class UsersExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return Auth::user()->getrecs();
    }
}

but when I try to visit the route related to this export I get:

"Class 'App\Exports\Auth' not found"

how to solve this?


Solution

  • You forgot to use Auth.

    <?php
    
    namespace App\Exports;
    
    use Auth;
    use App\User;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Maatwebsite\Excel\Concerns\FromCollection;
    
    class UsersExport implements FromCollection
    {
        /**
        * @return \Illuminate\Support\Collection
        */
        public function collection()
        {
            return Auth::user()->getrecs();
        }
    }
    

    FYI, Now Laravel has released version 7.