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
My Answer:
It looks like the issue is with the way you are trying to resolve the controller in your service provider.
In your `MyPackageServiceProvider.php` file, make sure you are using the correct namespace and case for the controller.
For example, if your controller is located in the `Controllers` folder within your package and has the namespace `Company\MyPackage\Controllers`, you should resolve it like this:
php
use Company\MyPackage\Controllers\ApplyController;
// Inside a method in your service provider
app()->make(ApplyController::class);
Make sure that the namespace and case of the controller match the actual file structure and namespace in your package.
After making these changes, run `composer dump-autoload` to update the autoloader and see if the issue is resolved.
Rate this post
5 of 5 based on 8939 votesComments