Laravel package namespace can't find controller composer 2 - php

I've recently updated my custom Laravel package's namespace after my original question was closed, I've followed the suggestion from the attached answers in my original question and just need some pointers here.
Composer 1 throws a warning regarding my class, so I've gone ahead and updated my namespace to be lowercase since, and most of the warnings have gone away in terms of the controllers, but now, when I run composer dump my error is that:
Target class [company\mypackage\ApplyController] does not exist.
Previously, my class had uppercase letters:
namespace Company\MyPackage;
and my folders http and controllers had an uppercase letter, they're now lowercase and I don't know why I'm getting an error now?
The full error now is:
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
Illuminate\Contracts\Container\BindingResolutionException
Target class [company\mypackage\ApplyController] does not exist.
at vendor/laravel/framework/src/Illuminate/Container/Container.php:835
831▕
832▕ try {
833▕ $reflector = new ReflectionClass($concrete);
834▕ } catch (ReflectionException $e) {
➜ 835▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
836▕ }
837▕
838▕ // If the type is not instantiable, the developer is attempting to resolve
839▕ // an abstract type such as an Interface or Abstract Class and there is
+6 vendor frames
7 /Users/user/Sites/laravel-packages/mypackage/src/MyPackageServiceProvider.php:18
Illuminate\Foundation\Application::make("company\mypackage\ApplyController")
+7 vendor frames
15 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Related

Illuminate\Contracts\Container\BindingResolutionException - Target class [CommandMakeCommand] does not exist

Using Laravel 8.75 and trying to upgrade to php 8.1 in composer.json to "php": "^8.1" and receive the error of Illuminate\Contracts\Container\BindingResolutionException - Target class [CommandMakeCommand] does not exist.
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it.
Use symfony/mailer instead.
Generating optimized autoload files
Illuminate\Foundation\ComposerScripts::postAutoloadDump
#php artisan package:discover --ansi
Illuminate\Contracts\Container\BindingResolutionException
Target class [CommandMakeCommand] does not exist.
at
vendor/laravel/framework/src/Illuminate/Container/Container.php:879
875▕
876▕ try {
877▕ $reflector = new ReflectionClass($concrete);
878▕ } catch (ReflectionException $e) {
879▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
880▕ }
881▕
882▕ // If the type is not instantiable, the developer is attempting to resolve
883▕ // an abstract type such as an Interface or Abstract Class and there is
+13 vendor frames
14 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
Script #php artisan package:discover --ansi handling the post-autoload-
dump event returned with error code 1
i also had same problem, in my case nwidart/laravel-modules package upgraded to 8.3 version, i downgraded to 8.2 version and problem solved
see here: https://docs.laravelmodules.com/v9/introduction
If you have an existing config file, and you get an error:
Target class [CommandMakeCommand] does not exist
Then the config file will need updating first import the commands class:
use Nwidart\Modules\Commands;
Next replace the commands array with:
'commands' => [
Commands\CommandMakeCommand::class,
Commands\ComponentClassMakeCommand::class,
Commands\ComponentViewMakeCommand::class,
Commands\ControllerMakeCommand::class,
Commands\DisableCommand::class,
Commands\DumpCommand::class,
Commands\EnableCommand::class,
Commands\EventMakeCommand::class,
Commands\JobMakeCommand::class,
Commands\ListenerMakeCommand::class,
Commands\MailMakeCommand::class,
Commands\MiddlewareMakeCommand::class,
Commands\NotificationMakeCommand::class,
Commands\ProviderMakeCommand::class,
Commands\RouteProviderMakeCommand::class,
Commands\InstallCommand::class,
Commands\ListCommand::class,
Commands\ModuleDeleteCommand::class,
Commands\ModuleMakeCommand::class,
Commands\FactoryMakeCommand::class,
Commands\PolicyMakeCommand::class,
Commands\RequestMakeCommand::class,
Commands\RuleMakeCommand::class,
Commands\MigrateCommand::class,
Commands\MigrateRefreshCommand::class,
Commands\MigrateResetCommand::class,
Commands\MigrateRollbackCommand::class,
Commands\MigrateStatusCommand::class,
Commands\MigrationMakeCommand::class,
Commands\ModelMakeCommand::class,
Commands\PublishCommand::class,
Commands\PublishConfigurationCommand::class,
Commands\PublishMigrationCommand::class,
Commands\PublishTranslationCommand::class,
Commands\SeedCommand::class,
Commands\SeedMakeCommand::class,
Commands\SetupCommand::class,
Commands\UnUseCommand::class,
Commands\UpdateCommand::class,
Commands\UseCommand::class,
Commands\ResourceMakeCommand::class,
Commands\TestMakeCommand::class,
Commands\LaravelModulesV6Migrator::class,
],
Just add this line:
use Nwidart\Modules\Commands\CommandMakeCommand;
in first of config/modules.php file as a namespace
Above namespace will resolve only commandMakeCommand issue, but if you want to set all command namespace then you need to add the namespace at the top.
namespace Nwidart\Modules\Commands;
Hope this helps (backup your project first):
First remove nwidart/laravel-modules by running: composer remove nwidart/laravel-modules
Then remove config/modules.php by deleting it.
Reinstall nwidart/laravel-modules by running: composer require nwidart/laravel-modules
Source:
Githubhot, the answer by mohamedsharaf
If someone is still looking for the answer so follow these steps
As mentioned in this link see here: https://docs.laravelmodules.com/v9/introduction
If you have an existing config file, and you get an error:
Target class [CommandMakeCommand] does not exist
Then the config file will need updating first import the commands class, and in your config folder update the modules.php file includes
use Nwidart\Modules\Commands;
Then replace the commands array with: add Commands\ before each value or simple copy and replace the array
'commands' => [
Commands\CommandMakeCommand::class,
Commands\ComponentClassMakeCommand::class,
Commands\ComponentViewMakeCommand::class,
Commands\ControllerMakeCommand::class,
Commands\DisableCommand::class,
Commands\DumpCommand::class,
Commands\EnableCommand::class,
Commands\EventMakeCommand::class,
Commands\JobMakeCommand::class,
Commands\ListenerMakeCommand::class,
Commands\MailMakeCommand::class,
Commands\MiddlewareMakeCommand::class,
Commands\NotificationMakeCommand::class,
Commands\ProviderMakeCommand::class,
Commands\RouteProviderMakeCommand::class,
Commands\InstallCommand::class,
Commands\ListCommand::class,
Commands\ModuleDeleteCommand::class,
Commands\ModuleMakeCommand::class,
Commands\FactoryMakeCommand::class,
Commands\PolicyMakeCommand::class,
Commands\RequestMakeCommand::class,
Commands\RuleMakeCommand::class,
Commands\MigrateCommand::class,
Commands\MigrateRefreshCommand::class,
Commands\MigrateResetCommand::class,
Commands\MigrateRollbackCommand::class,
Commands\MigrateStatusCommand::class,
Commands\MigrationMakeCommand::class,
Commands\ModelMakeCommand::class,
Commands\PublishCommand::class,
Commands\PublishConfigurationCommand::class,
Commands\PublishMigrationCommand::class,
Commands\PublishTranslationCommand::class,
Commands\SeedCommand::class,
Commands\SeedMakeCommand::class,
Commands\SetupCommand::class,
Commands\UnUseCommand::class,
Commands\UpdateCommand::class,
Commands\UseCommand::class,
Commands\ResourceMakeCommand::class,
Commands\TestMakeCommand::class,
Commands\LaravelModulesV6Migrator::class,
],
You can try to downgrade nwidart/laravel-modules version in composer.json file. Just change this line to the below line.
"nwidart/laravel-modules": "8.2.*"
Then delete composer.lock file and now, run this command.
composer install
If previous reply doesn't work for you,
If still not work after changing the version in composer.json as well as deleting the composer.lock and vendors, you can fix the version like this
"nwidart/laravel-modules": "8.2.*"
delete composer.lock and vendor and run
composer install
This Is Not Related Routes Or Any Other Parts Of Your App ,
When You Cant Run Composer Update Or Artisan Commands
You Have Problem In Booting Laravel , In This Case :
Go To Your Config Folder Open Modules File And Check "Command" Key
My Problem Fixed By This Way !
Good Day !

Cannot resolve this error: "Target class [DatabaseSeeder] does not exist."

Many people have asked about this error: Target class [DatabaseSeeder] does not exist. It seems to have many root causes, but I cannot determine my root cause.
I am using Laravel 6.20.43. The software does not produce any errors when run in the browser.
The error
The error appears when I use this command: php artisan db:seed
Here is DatabaseSeeder.php:
<?php
namespace Database\seeds;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
use App\User;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* #return void
*/
public function run()
{
// factory$this->call(UsersTableSeeder::class);
// factory(App\User::class, 10)->create();
// dd('DatabaseSeeder.php TESTING...');
}
}
What have I tried?
I have tried to add a dd(...) inside DatabaseSeeder::run(). The dd(...) is not executed.
I have tried composer update. The update was performed nicely, but did not resolve the error.
I have tried several use clauses in DatabaseSeeder.php.
I have tried php artisan migrate:fresh
I have tried several combinations of solutions, for example to run migrations before dump-autoload and vice versa.
I have tried composer dump-autoload and this is the output:
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Generated optimized autoload files containing 4381 classes
I have tried to redirect the output of php artisan db:seed to xdebug so I can analyse step by step what is happening. Good luck is what I needed here, but I ran out of luck.
I have tried to examine the error using php artisan db:seed -vvv. Here is the full output:
Illuminate\Contracts\Container\BindingResolutionException : Target class [DatabaseSeeder] does not exist.
at /home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Container.php:805
801|
802| try {
803| $reflector = new ReflectionClass($concrete);
804| } catch (ReflectionException $e) {
> 805| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
806| }
807|
808| // If the type is not instantiable, the developer is attempting to resolve
809| // an abstract type such as an Interface or Abstract Class and there is
Exception trace:
1 ReflectionException::("Class DatabaseSeeder does not exist")
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Container.php:803
2 ReflectionClass::__construct()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Container.php:803
3 Illuminate\Container\Container::build()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Container.php:681
4 Illuminate\Container\Container::resolve()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:785
5 Illuminate\Foundation\Application::resolve()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Container.php:629
6 Illuminate\Container\Container::make()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:770
7 Illuminate\Foundation\Application::make()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php:76
8 Illuminate\Database\Console\Seeds\SeedCommand::getSeeder()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php:63
9 Illuminate\Database\Console\Seeds\SeedCommand::Illuminate\Database\Console\Seeds\{closure}()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php:129
10 Illuminate\Database\Eloquent\Model::unguarded()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php:64
11 Illuminate\Database\Console\Seeds\SeedCommand::handle()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
12 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Util.php:37
13 Illuminate\Container\Util::unwrapIfClosure()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
14 Illuminate\Container\BoundMethod::callBoundMethod()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
15 Illuminate\Container\BoundMethod::call()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Container/Container.php:590
16 Illuminate\Container\Container::call()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Console/Command.php:134
17 Illuminate\Console\Command::execute()
/home/billybob/laravel-cursus1/vendor/symfony/console/Command/Command.php:255
18 Symfony\Component\Console\Command\Command::run()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Console/Command.php:121
19 Illuminate\Console\Command::run()
/home/billybob/laravel-cursus1/vendor/symfony/console/Application.php:1009
20 Symfony\Component\Console\Application::doRunCommand()
/home/billybob/laravel-cursus1/vendor/symfony/console/Application.php:273
21 Symfony\Component\Console\Application::doRun()
/home/billybob/laravel-cursus1/vendor/symfony/console/Application.php:149
22 Symfony\Component\Console\Application::run()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Console/Application.php:93
23 Illuminate\Console\Application::run()
/home/billybob/laravel-cursus1/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:131
24 Illuminate\Foundation\Console\Kernel::handle()
/home/billybob/laravel-cursus1/artisan:37
I truly cannot understand how to debug the output of php artisan db:seed -vvv. All those files reside in the vendor directory, meaning I cannot examine the program flow easily. Please also explain how I can debug such an error by myself in the future.
It cannot find your DatabaseSeeder class because your namespace is incorrect.
You need to change the namespace of your DatabaseSeeder class from:
namespace Database\seeds;
to:
namespace Database\Seeders;
Make sure your composer autoload is setup correctly:
"autoload": {
"psr-4": {
"Database\\Seeders\\": "database/seeders/"
}
}
Alternatively, completely remove all namespaces from your DatabaseSeeder class and revert the above changes to composer.json and then run:
composer dump-autoload
then try running:
php artisan migrate:fresh --seed

TypeError on any artisan commands

Laravel Version: 7.23.0
PHP Version: 7.4.8
Database Driver & Version: MySQL v8.0.21
This morning I upgraded Laravel to version 7.23.0 due to the current vulnerability (https://blog.laravel.com/laravel-cookie-security-releases). But now I get the following error message with every Artisan Command:
php artisan package:discover --ansi
TypeError
Illuminate\Container\Container::bind(): Argument #2 ($concrete) must be of type Closure|string|null
at vendor/laravel/framework/src/Illuminate/Container/Container.php:238
234| // bound into this container to the abstract type and we will just wrap it
235| // up inside its own Closure to give us more convenience when extending.
236| if (! $concrete instanceof Closure) {
237| if (! is_string($concrete)) {
> 238| throw new \TypeError(self::class.'::bind(): Argument #2 ($concrete) must be of type Closure|string|null');
239| }
240|
241| $concrete = $this->getClosure($abstract, $concrete);
242| }
+11 vendor frames
12 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Facade\Ignition\IgnitionServiceProvider))
+5 vendor frames
18 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Since I think this would be a more noticeable bug, and I haven't found an issue on GitHub, I didn't open a new one and ask for help here :)
However, I don't really have any idea what exactly might be causing the problem.
Thanks to Abdel-aziz hassan for the link (https://github.com/laravel/framework/pull/33539).
I found out that facade/ignition was on an old version. I updated it and now it works.
Thanks guys!
In my case using instance instead of bind helps me.
$app->instance(Service::class, $serviceInstance)
instead
$app->bind(Service::class, $serviceInstance)

Composer dump-autoload error when a vendor is in a package konekt/concord

the composer throws error on root folder:
Class 'Konekt\Concord\BaseBoxServiceProvider' not found
Script #php artisan package:discover handling the post-autoload-dump event
returned with error code 255
While if I trying it in the package then the class is found. The files are the next:
namespace Ecommerce\Shop\Providers;
use Konekt\Concord\BaseBoxServiceProvider;
class ShopServiceProvider extends BaseBoxServiceProvider{
and this class isn't found anymore:
namespace Konekt\Concord;
abstract class BaseBoxServiceProvider extends BaseServiceProvider{
The vendor of it and the Src are in packages/ecommerce/shop (/vendor or /src).
Thanks for helping.

Script #php artisan package:discover handling the post-autoload-dump event returned with error code 255

I moved my project from desk to another.
When I run php artisan it does not work.
I tried to run composer update, but it returns the error
Script #php artisan package:discover handling the post-autoload-dump event returned with error code 255
This is how I solved this after an upgrade from laravel version 6.x - 7.x:
In App\Exceptions\Handler changed
//Use Exception;
Use Throwable;
Then methods to accept instances of Throwable instead of Exceptions as follows:
//public function report(Exception$exception);
public function report(Throwable $exception);
//public function render($request, Exception $exception);
public function render($request, Throwable $exception);
In config\session.php:
//'secure' => env('SESSION_SECURE_COOKIE', false),
'secure' => env('SESSION_SECURE_COOKIE', null),
Then run composer update
I solved the problem this way:
cd bootstrap/cache/
rm -rf *.php
The bootstrap directory contains the app.php file that initializes the structure. This directory also houses a cache directory that contains structure-generated files for performance optimization, such as files and route cache services. Laravel stores configuration files, provider, and cached services to optimize the fetching of this information. The problem with me was when the other developer ran the 'php artisan config: cache' command on your machine and since the cache folder contains files that can be deleted, I deleted them and solved the problem.
If this happened after Laravel update from 6.x to 7.x, then this could be due to the update of Symfony. See the upgrade guide of this part:
https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades
I was upgrading my Laravel from 5.8 to 8.0 and I got this error.
So my fixes were
As #nobuhiroharada mentioned that I had missed .env file in my project
Second is that Laravel removed Exception and replaced it with Throwable. So we need to fix that in our app\Exceptions\Handler.php. One can refer Medium.com for the error fix.
In the upgrade guide of Laravel 8.x you need to update the dependencies like this
Next, in your composer.json file, remove classmap block from the autoload section and add the new namespaced class directory mappings:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
Finally from bootstrap\cache delete the cache files and run composer update.
These 5 steps might help you remove the error you are facing in your Laravel Project.
This happens because you have upgraded to Laravel 7.
To fix it, update app/Exceptions/Handler.php like so:
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable; // <-- ADD THIS
class Handler extends ExceptionHandler
{
public function report(Throwable $exception) // <-- USE Throwable HERE
{
parent::report($exception);
}
public function render($request, Throwable $exception) // AND HERE
{
return parent::render($request, $exception);
}
}
This is documented in the official upgrade guide here:
https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades
I got the same problem in Win 8 and solve it:
Here is the steps.
Step-1: Go to your project directory
Step-2: And type command cd bootstrap/cache/
Step-3: Again type command del -rf *.php
Step-4: Update your composer composer update
Step-5: Now you are done: php artisan serve
Thanks.
Do you have .env file in your new project?
I had same error message. When I add .env file, error is gone.
success message like this.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover
Discovered Package: fideloper/proxy
Discovered Package: ixudra/curl
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: socialiteproviders/manager
Package manifest generated successfully.
I hope this will help you.
maybe you have an error in the project code (for example, in routes or controller). This may be one of the reasons for this error.
In my project, the web.php file has a syntax error. I defined this when I started the php artisan command
C:\OSPanel\domains\lara.shop.loc>php artisan
In web.php line
syntax error, unexpected end of file
Same issue when I update laravel from 6.x to 7.x
I tried the most voted answer but it didn't work, then I used php artisan serve I noticed that:
RuntimeException
In order to use the Auth::routes() method, please install the laravel/ui package.
Try composer require laravel/ui maybe it will work.
I solve this error by deleting the vendor table then run composer update. I'm using Laravel 7. So, if you are not updating from the older Laravel version, maybe this is the solution.
I had this same problem when running composer update in a Laravel project. In the package.json it's configured to run artisan package:discover, which failed with:
Class 'Symfony\Component\Translation\Translator' not found in vendor/nesbot/carbon/src/Carbon/Translator.php on line 18
When I looked in the vendor/symfony/translation directory I found that it was completely empty, which explained the error.
The solution was to completely delete the vendor directory and then re-run composer update. This was the only way that I was able to make composer install the missing files.
I deleted composer.lock file and ran composer update.
That solved mine
I had the same issue, my problem was the PHP version of the server account did not match my Docker container. The SSH terminal was using the global php version for the server.
php -v
Confirm it's the version your project needs.
Composer did warn me that a higher php version was required but I rm -rf'd /vendor and ./composer.lock without paying too much attention to the warnings!
Got the same problem.
php artisan doesn't work.
composer install got error:
Script #php artisan package:discover handling the post-autoload-dump event returned with error code 255
And this works for me.
When I switch another linux user. It works.
some files are owned by another linux user.
So I use root account and change all the project file to the specific user,
chown -R www:www project/
and use that user to execute composer cmd
and then it works.
My case/solution, in case it helps anyone...
I copied my repo over from my old Windows computer to a new one, and installed the latest php.
composer install was returning:
Root composer.json requires php ^7.1.3 but your php version (8.1.10) does not satisfy that requirement
...which I thought was odd (assuming 8 satisfied ^7), so I continued on with composer install --ignore-platform-reqs, and ended up with this particular issue.
After trying a bunch of other possible solutions, what ended up working for me was simply downgrading to the same PHP version from my old machine (7.4.33).
This is not an actual error. If you look a bit above you'll see the actual error.
In my case, there was an error in my code:
PHP Fatal error: Declaration of
App\Exceptions\Handler::render($request, App\Exceptions\Exception $exception)
must be compatible with
Illuminate\Foundation\Exceptions\Handler::render($request, Throwable $e)
It is not possible to tell you what is actually a problem in your code, so you have to look real reason for this error in your stack trace.
In my case there is missing folder and its file Kernel.php in
app/Console
So I created app/Console/Kernel.php using code from previous project.
Now everything working fine.
Make sure your config\constants.php (and/or resources\lang\en\local.php) has no syntax errors. I get this error a lot by missing commas in constants.php file.
If you have this error the simplest way is you can try using composer install instead of composer update
I deleted my project I created a new folder and cloned the repository again and after that I gave composer install / update.
I got the same problem in Win 10 and solve it:
Here is the steps.
Step-1: Go to your project directory
Step-2: Update your composer
composer update
Step-3: Now you are done: php artisan serve
Nothing worked, so I installed a new project, and I read Handler.php in App\Exceptions, it was different, probably because I copied some solution and Internet and deleted the following:
protected $dontReport = [
//
];
protected $dontFlash = [
'password',
'password_confirmation',
];
I copy here all of Handler.php generated by laravel 7.5, may be useful for someone:
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* #var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* #var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* #param \Throwable $exception
* #return void
*
* #throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* #param \Illuminate\Http\Request $request
* #param \Throwable $exception
* #return \Symfony\Component\HttpFoundation\Response
*
* #throws \Throwable
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
}
For me it was related to Kernel.php
I was adding new schedule task into the Kernel. I also updated some controllers, views, and installed twilio extension.
The error did not provide more information than
Script #php artisan package:discover handling the post-autoload-dump event returned with error code 255
#Suresh Pangeni refences the Kernel.php doc so I checked by doc that is in PROJECTFOLDER\app\Console\Kernel.php
protected $commands = [
Commands\Inspire::class,
Commands\Test::class
\App\Console\Commands\Message::class,
];
Missing Comma between Commands\Test::class and the next line didn't let me proceed. It provided no further warning or information when I ran composer dump-autoload.
Hope this can help someone else that has a similar issue!
I had the same error today, the causes are as follows:
cause 1: the env file contains space in one of the configuration.
cause 2: incorrect configuration of the Handler file belonging to the App\Exceptions namespace;
cause 3: incorrect configuration of a file inheriting ExceptionHandler
I was using Laravel 9.x and got the same error after trying to install this package maatwebsite/excel!
thanks to #samuel-terra and #dqureshiumar there is the solution worked for me:
clear bootstrap/cache:
cd bootstrap/cache/
rm -rf *.php
then run composer update:
composer update
My problem was __construct method.
composer.json
"php": "^8.1",
"laravel/framework": "^9.19",
Handler.php
The problem originates from this code:
this->container->make(FlasherInterface::class);
My solution, I removed the construction directly and the problem is solved.
public function __construct(Container $container)
{
parent::__construct($container);
$this->flasher = $this->container->make(FlasherInterface::class);
//$this->request = $this->container->get(Request::class);
}
Getting this error when my composer version 2.x then i rollback this
composer self-update --1
Now its perfectly working

Categories