1

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';)?

JAAulde
  • 19,250
  • 5
  • 52
  • 63
bantya
  • 576
  • 11
  • 23
  • Possible duplicate of [What is autoload in php?](http://stackoverflow.com/questions/3607543/what-is-autoload-in-php) – JAAulde Oct 18 '16 at 18:53
  • It uses psr loader check this [link](http://www.php-fig.org/psr/psr-4/) – Tim Oct 18 '16 at 18:48

2 Answers2

5

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

Kevin
  • 25,946
  • 2
  • 19
  • 21
2

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).

Dekel
  • 60,707
  • 10
  • 101
  • 129