Loading custom php file in Laravel without composer dump-autoload

You can add your namespace to the autoloader like this :

$loader = require 'vendor/autoload.php';
$loader->add('NameSpace', 'Path to directory'); // PSR-0 loading
$loader->addPsr4('NameSpace\\', 'Path to directory'); // PSR-4 loading

Doc : https://getcomposer.org/apidoc/1.0.0/Composer/Autoload/ClassLoader.html#method_add


The code needs to be added in the bootstrap.php file : you need to extend the base autoloader which is loaded with this line : require __DIR__.'/../vendor/autoload.php';

replace this line with $loader = require __DIR__.'/../vendor/autoload.php'; and add your custom namespace to the autoloader.

Tags:

Php

Laravel