Support the ongoing development of Laravel.io →
posted 2 years ago
Laravel
Last updated 2 years ago.
0
moderator

Hello @wolfenste,

Do you have run composer install in your project? If it is a Laravel project then it should be loaded with the autoloader. You can find the file in <projectroot>/vendor/laravel/framework/src/Illuminate/Collections/Collection.php

wolfenste liked this reply

1

Yeah, there is a Collection.php at vendor/laravel/framework/src/Illuminate/Collections/Collection.php But I talk about Illuminate/Support/Collection.php

The project is made via composer create-project laravel/laravel name

Look, in my controller I have: use App\Models\PagesInfo Then in __invoke () method of my controller I have: $data = PagesInfo::select ('name') ->where ('id', 1) ->get ()

The get () method returns an object Illuminate\Database\Eloquent\Collection that extends Illuminate\Support\Collection

I can't find the file vendor/laravel/framework/src/Illuminate/Support/Collection.php

0

Or you say that by magic the autoloader loads in fact Illuminate\Collections\Collection when it sees Illuminate\Support\Collection ?

Ok, that class Illuminate\Collections\Collection is under the namespace Illuminate\Support... Is this a mistake or by intention? It doesn't look consistent to me. I was expecting that namespaces match directories.

Last updated by @wolfenste 2 years ago.
0
moderator Solution

Most of the time the namespaces match the directories. In the composer.json for laravel/framework you can see that there is an exception for Illuminate\Support https://github.com/laravel/framework/blob/8.x/composer.json#L111 I suspect it is to keep a little more organized.

Do you get any error / warning if you run composer dump-autoload that can maybe point out why you get your error.

And how do you run your code? (Is it a plain php file / controller / route / other)

wolfenste liked this reply

1
Solution selected by @driesvints

Thank you! The code works fine. I did not know where the magic comes from. And I want to see that "hidden" class. I get it, I should search the answer in composer.json file.

tvbeek liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Wolf Enste wolfenste Joined 15 Jan 2022

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.