Jason Paddle Jason Paddle - 24 days ago 11
PHP Question

Loading custom class in laravel without dump autoload

I have directory

/libraries/
under
/app/
. Libraries is suppose to hold all custom files and classes. I'm putted new file there but it doesn't work because I need to
dump-autoload
.. The problem is that I can't do this. No access to terminal etc..

I have this in
composer.json


"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/libraries", // <<----- this one
"app/tests/TestCase.php"
]
},


Another file which is in libraries from the very beginning is working just fine.

My question is how can I load this new file?

Answer

You can try something which I recently tried and it's worked for me. Navigate to vendor/composer/. Since you've said that you have one php file in libraries and it's working this means you will have it in followed files and you can copy/paste the lines and change with your files.

First open file autoload_classmap.php and add at the bottom of the array

'yourfile' => $baseDir . '/app/libraries/yourfile.php',

Second open file autoload_static.php and at the bottom add your file again

public static $classMap = array (
    ...
    'yourfile' => __DIR__.  '/../..' . '/app/libraries/yourfile.php',

Save both files and reload. In my case this loaded the files without need of auto-dump.

Comments