0
I can’t access Spreadsheet class, it appears:
use Illuminate\Database\Eloquent\Model;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Excel extends Model
{
public function excelPropostas($ini = null, $fim = null, $qtd = null)
{
$spreadsheet = new Spreadsheet();
...
}
}
Class of the Spreaadsheet:
namespace PhpOffice\PhpSpreadsheet;
class Spreadsheet
{
..
}
but makes a mistake:
Class 'PhpOffice\PhpSpreadsheet\Spreadsheet' not found
Can someone help me?
If you installed it by Composer, all you had to do was use the namespace
PhpOffice\PhpSpreadsheet\Spreadsheet
, without thisVendor
at first, something else does not move its dependency out of the vendor folder of the project, and the namespace of a file does not depend on the location of the file in the directory, but on which namespace is used in the file that you import, by convention the same namespace is used for the directory hierarchy. I recommend doing a better search for namespace in php. https://answall.com/questions/151487/namespaces-e-use-quando-usar-e-para-que-servem.– fajuchem
I edited the question, in fact it the directory, but still, it does not find the class. Unless the problem is to load it in Laravel’s own Model format.
– Glenys Mitchell
You installed him by the Commodore?
– fajuchem
Yes, I installed it by Composer.
– Glenys Mitchell
I recommend removing the vendor folder from the project and installing again, and then generating autoload again, as follows: Remove vendor folder
rm -rf vendor
then install the dependenciescomposer install
and lastlycomposer dump-autoload
. And I give the tip never manually change any file inside the vendor directory, it will only bring future problems.– fajuchem
The error is in the class call: $Spreadsheet = new Spreadsheet(); This folder is not native to the Laravel, so there is no point in reinstalling it. But I’ll try to dump-autoload.
– Glenys Mitchell
Didn’t work..
– Glenys Mitchell