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
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
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.
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)
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.