The first three lines of database\seeds\DatabaseSeeder.php
are:
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder { ... }
The Illuminate\Database\Seeder
namespace points to vendor/laravel/framework/src/Illuminate/Database/Seeder.php
.
How does Laravel require the files from relatively complex directory structures so easily just by using its namespaces?
Where are the files are actually loaded with require
(like: require 'path\to\file';
)?
It uses psr loader check this link
Laravel
Laravel uses PSR-4 autoloading via Composer to load files. Mainly, composer manages how classes and files are loaded.
Custom Framework
Most PHP frameworks today, like Laravel, use spl_autoload_register() to handle the dynamic loading of class files when a class has not been loaded. PSR-4 is a community standard from the PHP-FIG used to describe the format of classes and how their files should be written.
The PHP-FIG has example autoloaders you can modify for your own projects.
Relevant links
If you open the index.php
file you will see there in line 22:
require __DIR__.'/../bootstrap/autoload.php';
This require the autoload.php
file, which loads the composer
autoloader:
require __DIR__.'/../vendor/autoload.php';
Which handles all the automatic loading of the different files (classes/libraries).