Target class [App\Services\UserService] does not exist in laravel package - Stack Overflow

admin2025-04-16  4

I am developing a package based on the an api for admin panel I did using laravel and Service Archicture. I hace included Services folder in the src folder. I now want to change it into a package however I am getting error.

{
    "message": "Target class [App\\Services\\UserService] does not exist.",
    "exception": "Illuminate\\Contracts\\Container\\BindingResolutionException",
    "file": "D:\\microvision\\projects\\_test\\packages\\test-project-1\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
    "line": 946,

I am developing a package based on the an api for admin panel I did using laravel and Service Archicture. I hace included Services folder in the src folder. I now want to change it into a package however I am getting error.

{
    "message": "Target class [App\\Services\\UserService] does not exist.",
    "exception": "Illuminate\\Contracts\\Container\\BindingResolutionException",
    "file": "D:\\microvision\\projects\\_test\\packages\\test-project-1\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
    "line": 946,
Share Improve this question edited Feb 4 at 5:22 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Feb 3 at 18:29 Sospeter Mong'areSospeter Mong'are 1211 silver badge11 bronze badges 2
  • Ensure App\Services\UserService exists and has the right namespace – Emeka Mbah Commented Feb 3 at 22:38
  • Don't use App as your root namespace if you are developing a package since that will conflict with the root namespaces of most people that would want to use the package – apokryfos Commented Feb 3 at 23:28
Add a comment  | 

1 Answer 1

Reset to default 0

You're likely referencing the wrong namespace. In your package, update your service bindings from App\Services\UserService to the correct package namespace (e.g., Vendor\Package\Services\UserService), adjust your composer.json autoload settings accordingly, and run composer dump-autoload.

转载请注明原文地址:http://www.anycun.com/QandA/1744756407a87171.html