I decided to run "composer update" command another time to get the app back up to date but now it's completely broken as it can't find a certain class anymore.
Fatal error: Class 'App\Application' not found in /home/rlvpr/public_html/webroot/index.php on line 33
All files in the vendor folder have been properly uploaded, so yes also all the composer autoload class mappings ...
I really have no clue what I should do now :/
Anyone got any suggestions?
Thanks!
Try running composer dumpautoload.
If that doesn't work, check your composer.json for the autoload section:
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
Then dump autoload again. Of course, tweak the source folder path to suit where your namespace folder is!
Run:
composer dump-autoload
See also dump-autoload
Related
I'm trying to get started with nwidarts modular laravel architecture. I just got done installing it according to it's site: https://nwidart.com/laravel-modules/v2/basic-usage/creating-a-module
Now when I run the command php artisan module:make <module-name> I get the error:
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "module" namespace.
I am running this in the root folder of my laravel app. So I am not entirely sure I installed it in the right place but there is an nwidart folder and stuff in my apps vendor folder so I guess I did it right? What did I do wrong?
follow the instructions on command
step 1: composer require nwidart/laravel-modules
step 2: php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
step 3: insert in composer.json
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
step 4: composer dump-autoload
Wanted to install Laravel-Excel (Maatwebsite) package manually without composer, but I dont know how.
Why? Because I have a laravel project in a free hosting server setup by other guy, and I can only access using Filezilla to edit/download/upload the codes.
If only Filezilla allow a command prompt that could use "composer update", then it will be easier.
I got solution!
I cant use composer on my company because of secure network. But i can download zip form github and install it manual. The below is my example for HTMLPurifier:
download and extract library mews/purifier to vendor directory https://github.com/mewebstudio/Purifier
add below line in vendor/composer/autoload_psr4.php
This sentence will load all of file from vendor/mews/purifier/src and autoload in namespace Mews\Purifier\
'Mews\\Purifier\\' => array($vendorDir . '/mews/purifier/src'),
Sometime you need add library into autoload_namespaces.php intead of, please read in
https://getcomposer.org/doc/04-schema.md#autoload
You got Mews\Purifier\Facades\Purifier not found if public config before finish step 3
$ php artisan vendor:publish
--provider="Mews\Purifier\PurifierServiceProvider"
add below json in vendor/composer/installed.json
This for composer history, providers and aliases will be load in config/app/php for register new provider
{
"name": "mews/purifier",
"version": "v2.0.12",
"type": "library",
"extra": {
"laravel": {
"providers": [
"Mews\\Purifier\\PurifierServiceProvider"
],
"aliases": {
"Purifier": "Mews\\Purifier\\Facades\\Purifier"
}
}
},
"autoload": {
"psr-4": {
"Mews\\Purifier\\": "src/"
}
}
},
Now you run this config, then vendor/mews/purifier/config will be move to config folder
$ php artisan vendor:publish
--provider="Mews\Purifier\PurifierServiceProvider"
Add the package to the vendor folder. You can upload it using filezilla
Add a reference in \vendor\composer\autoload_namespaces.php
Add a reference in \vendor\composer\autoload_psr4.php
Source laravel.io
it's easy to do it by following this
download the package and set the files in app folder
YourProject/app/Laravel-Excel/
and then add the path to composer.json in autoload
"autoload": {
...
"classmap": [
"database/seeds",
"database/factories"
"app/Laravel-Excel"
],
...
},
Run the composer dump-autoload
the solution refs to this question referance answer
download the package locally and then upload the package folder (found under vendor) along with the updated composer.json
Depending on how strict the server is, you could SSH into your Server. But doing it locally then uploading the required files is usually the way to go.
You might need to run composer autodump if you don't wipe the cache.
If everything works on local environment then copy your package and composer folder to server which is located at vendor
upload \vendor\maatwebsite
copy \vendor\maatwebsite\excel\src\config\excel.php to \config\excel.php
In a project (on which work 2), we are forced to make a "php composer.phar dump-autoload" and "php composer.phar dump-autoload -o" every time we add a new file (a new class in our web project).
If we do not type these lines of command, the autoloader dial tells us that this class is not found ...
Whereas with personal projects, I have never been compelled to type these command lines for each new class of creation.
In my composer.json I have put this:
"autoload": {
"psr-4" : {
"App\\": "app/",
"Database\\": "app/",
"Helpers\\": "app/",
"": [
"app/",
"lib/"
]
}
}
Thus I does not understand, why, for every time we add a file in the folder " app ", we have to make "php composer.phar dump-autoload" and "php composer.phar dump-autoload -o" ...
ps : I have Classes without Namespace in directories "app" and "lib".
Will you have an idea of where it could come please?
Thank you.
The only reason for having to dump the autoloader after adding a new class is when you are using classmap autoloading, and no PSR-0 or PSR-4.
This should be clearly indicated in the composer.json file of that application, which would be something like "autoload":{"classmap":[...]}.
If this is NOT present, there would be no requirement to dump the autoloader.
If however composer dump-autoload does not really work, and composer dump-autoload -o is needed, you have errors in your PSR definition of autoloading.
I'm confused whether your excerpt from your composer.json is from your nonworking example or not - all I can say is that it is supposed to work without dumping. It still is not optimal, though.
I created folder name - Birds and in this folder i created class Birds.php then add this to composer.json,
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Birds\\": "Birds/",
}
},
To load i have to run - composer dump-autoload -o and that's fine for first time to take that folder, But then i created new interface class like this :
namespace Birds\Validator;
interface BadgeInterface
{
public function test();
}
Interface class not working until in run composer dump-autoload,
My question is why i need to run this every time ? i am using laravel as framework.
Thanks
That's just how composer works. Laravel is just a PHP framework, so it is not able to run composer or other tool all the time for you.
If you need to automatically add files all the time, you can just use cron or Laravel's schedule command. It will do all the work for you every 5 minutes, for example.
This is cause when you create any class composer folder autoload.php can't update . that cause you need to run it manually . it clear you when you install any package at last command there run is composer autoload to update all reference in autoload.php file
I can't use composer to handle my dependencies due to the corporate firewall. At the moment I'm trying to use Barry vd Heuvel's DomPDF wrapper for Laravel and tried to:
Download the zipfile from Github (master)
Updated composer.json (not sure if its needed, but did it anyway) and added "barryvdh/laravel-dompdf": "*" in the require container.
Create the folder structure: vendor/barryvdh/laravel-dompdf
Place all files from the package in there (config-folder, src-folder and the files .gitignore, composer.json and readme.md)
Add the service provider and facade in my app.php. Service provider is listed as Barryvdh\DomPDF\ServiceProvider::class and the facade is aliased like 'PDF' => Barryvdh\DomPDF\Facade::class
Ran composer dump-autoload
After refreshing the browser I'm getting Class 'Barryvdh\DomPDF\ServiceProvider' not found. I also tried to run php artisan cache:clear and php artisan dump-autoload but the last one fails over the fact it can't find Barryvdh\DomPDF\ServiceProvider.
What have I forgotten to do to make it work?
Update
I've tried the suggested answer from Wouter J and the composer.json now looks like:
..
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Barryvdh\\DomPDF\\": "vendor/barryvdh/laravel-dompdf/src"
},
..
I've verified if the composer dump-autoload had any effect but I think it had. Because the entry is now also listed in vendor/composer/autoload_psr4.php like:
return array(
// more entries
'Barryvdh\\DomPDF\\' => array($vendorDir . '/barryvdh/laravel-dompdf/src'),
'App\\' => array($baseDir . '/app'),
);
I believe at this point this is working, but the Facade isn't responding. When I try to call something like PDF::loadView(...) and I let PhpStorm import the class (vendor/barryvdh/laravel-dompdf/src/PDF.php) it throws an error I can't call the method loadView statically. According to the documentation I should be able to call it like this:
$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');
But that results in Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically, assuming $this from incompatible context on my end.
Suggestions?
Composer autoload still doesn't know anything about how to download the package. You have to configure autoloading like this:
{
"autoload": {
"psr-4": { "Namespace\\Of\\The\\Package\\": "vendor/the/package" }
}
}
I know this question is old, but since I don't see any solution, here is mine: I had exactly the same problem. Was able to solve by running composer dumpautoload on my localhost and then copied the folder 'vendor/composer' to the shared hosting without an SSH access. Hope this will help someone in similar situation.
The problem addresses that application don't know about DomPDF\ServiceProvidor or anything related to DomPDF because barryvdh/laravel-dompdf itself depends dpmpdf/dompdf package which is still missing and does not comes with barryvdh/laravel-dompdf
the package dompdf/dompdf also depends on several extension i.e.
PHP version 5.3.0 or higher
DOM extension
GD extension
MBString extension
php-font-lib
php-svg-lib
have a look at package here https://packagist.org/packages/dompdf/dompdf download this and put in your vendor directory then update your composer dumpautoload it should be working