Laravel version 5.6
I'm attempting to add some classes to my project via files under autoload.
Composer.json
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
},
"files" : [
"app/helpers/dbUsers.php",
"app/helpers/dbMoodChart.php"
]
},
Whenever I do a composer dump-autoload i get errors on both files saying files not found.
PHP Warning: Uncaught ErrorException:
require(C:\laravel-projects\project\vendor\composer/../../app/helpers/dbUsers.php):
failed to open stream: No such file or directory in
C:\laravel-projects\project\vendor\composer\autoload_real.php:66
Stack trace:
Warning: Uncaught ErrorException:
require(C:\laravel-projects\MoodWatch\vendor\composer/../../app/helpers/dbUsers.php):
failed to open stream: No such file or directory in
C:\laravel-projects\MoodWatch\vendor\composer\autoload_real.php:66
Stack trace:
The strange thing is its trying to load the files from the composer directory not the apps root folder. I've done this in another project and didn't have any issues. I've also compared my composer.json autoload sections on both projects and I can't see any syntax differences so I'm a bit puzzled as to why it's loading at the wrong location.
Has anyone seen anything similar before and be able to shed light on why it's doing this?
I found out the name of the file had a typo and once fixed both errors went away
Related
I'm converting my open source app as a package and it always throws error
PHP Fatal error: Class 'Laracommerce\Tests\TestCase' not found in .... on line 18
Based on other comments on every search I made, I just need to define it in my package composer.json's autoload-dev the location of my tests but still getting the error.
You are calling Laracommerce\Tests namespace but into the composer file you declared Laracommerce\Core\Tests
you need to:
a. change classes namespaces Laracommerce\Core\... to Laracommerce\...
b. or simply modify your composer file like this
"autoload":{
"psr-4": {
"Laracommerce\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Laracommerce\\Tests\\": "tests/"
}
},
Then you need to run composer dump-autoload
Try running a composer install, sometimes I get the same error but it gets fixed after that.
I have been working on migrating my Symfony 3.x project to the latest Symfony 4.x version. What I did was create a fresh install of Symfony 4.x and have been moving my bundle to Symfony 4 as a the main App namespace (renamed all my namespaces and use). I followed the correct folder structure in the Symfony 4 docs, but I obviously missed something.
When I try to do "bin/console server:run", I am presented with this error:
php bin/console server:run
Fatal error: Uncaught
Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load
class "Kernel" from namespace "App".
Did you forget a "use" statement for "Symfony\Component\HttpKernel\Kernel"?
in C:\wamp\www\DBViewer\bin\console:37
Stack trace:
#0 {main}
thrown in C:\wamp\www\DBViewer\bin\console on line 37
I checked line 37 in the console and all it was:
$kernel = new Kernel($env, $debug);
I've compared the the bin/console from my working Symfony 4 app to this Symfony 4 app, and it is the same. Any ideas what could be causing this?
Verfify your composer.json file. In Symfony 3.4 it used to be:
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
while in Symfony 4 it is simply:
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
In Symfony 4 your AppKernel.php must be directly in "src/" folder and not in "app/".
Hope this helps.
I'm working within the Laravel framework, and have a file loading successfully, pulled in through my Composer's files array. I can run composer update locally without issue -- I'm using the functions in the file.
However, when deploying to Digital Ocean, Composer throws an error, suggesting that it's looking for the file in the vendors directory (even though it's not looking there locally).
Fatal error: composerRequire0b4716b00b8bec4a70dbf5ea5e415661(): Failed
opening required
'/home/forge/myapp.com/vendor/composer/../../app/helpers/myHelper.php'
(include_path='.:/usr/share/php') in
/home/forge/myapp.com/vendor/composer/autoload_real.php on line 66
And the autoload section:
"autoload": {
"classmap": [
"database"
],
"files": [
"app/helpers/myHelper.php"
],
"psr-4": {
"App\\": "app/"
}
},
I think this question probably has what I need but I don't know if the difference between loading classes and files makes it irrelevant to this issue (clearly I'm confused about more than just this issue!):
How to I use Composer to autoload classes from outside the vendor?
try to delete all text in composer.lock and update composer
Using Laravel 5.2, I created a folder on my local machine inside of the app directory. The name of the folder is mailers. Inside of that folder are 2 classes.
I updated my composer.json file like this:
"autoload": {
"classmap": [
"database",
"app/foo"
],
"psr-4": {
"Acme\\": "app/"
}
},
After running composer update and composer dump-autoload, everything works fine on the local machine. However, after uploading the code to the live server, I run composer dump-autoload and receive the following error:
[RuntimeException]
Could not scan for classes inside "app/foo" which does not appear to be a file
nor a folder
How can I get my custom class recognized on the live server? Any help with this would be greatly appreciated. Cheers :)
Am trying structure my app in such a way that all my models will be in a dedicated directory(in my case Classified). I created the directory with Laravel app directory and added it to my my composer.json file. Below is the structure of my composer.json file:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Classified\\": "app/",
"Classified\\": "app/Classified"
}
},
Then I run composer dump-autoload in my terminal but I keep getting "Key Classified\ is a duplicate in ./composer.json at line 29
" and when I tried viewing my app in the browser i get:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Http\Kernel does not exist' in /home/vagrant/Workspace/codulabproducts/classified/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 736.
Line 29 in my composer.json file is
"Classified\\": "app/Classified"
I don't know what am doing wrong because I have followed these steps in my other project and everything went well.
You can define more than one directory for a namespace prefix. But in that case the value for the key must be a list and not a string (see the second example in the documentation):
{
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Classified\\": ["app/", "app/Classified"]
}
}
}
You can't have duplicated keys in your psr-4 mapping. It is supposed to define the root folder for given namespace and a namespace cannot have multiple roots.
Remove one of the mappings for Classified\ namespace.