0

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?

mark820850
  • 123
  • 1
  • 11

1 Answers1

1

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.

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68