So I have a public directory in my localhost that contains some classes that I want to be able to use in my current laravel project.
So how will I include these, external classes/files in laravel?
I tried to add these files in my composer.json file,
"autoload": {
"classmap": [
"database",
"../public_classes/priceClass.php"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"../public_classes/priceClass.php"
]
},
and do composer dump-autoload, then when I tried to call the function, it won't work.
You don't need to add anything in composer.json if you're using PSR-4. For example, you can create PHP file in \app\MyClasses\MyClass.php and use this namespace in custom class: namespace App\MyClasses.
Laravel will autoload this class for you.
I also wanted to include a few classes in my Laravel Project for that I just copied the files in a new directory(app/Libraries) and assigned Package name to all the classes and followed PSR-4 Autoloading standard for all those class files and I have added following code in my composer.json.
...
"autoload": {
"classmap": [
"app/Libraries",
],
...
hope this will solve your problem...
Happy to help!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With