0

I know the title topic sounds similar to other questions, but I've searched many topics on stackoverflow and none resolve my issue.

I am currently developing a package under Laravel ^8.12, below the content of the function that register my routes:

protected function registerRoutes(): void { Route::prefix('workflowmakr') ->namespace('AlvariumDigital\WorkflowMakr\Http\Controllers') ->as('workflowmakr.') ->middleware(config('workflowmakr.routes_middleware')) ->group(__DIR__ . '/../routes/api.php'); } 

And below is the content of the routes/api.php file:

<?php use Illuminate\Support\Facades\Route; Route::resource('actions', 'ActionController')->except(['created', 'edit']); Route::resource('scenarios', 'ScenarioController')->except(['created', 'edit']); Route::resource('statuses', 'StatusController')->except(['created', 'edit']); Route::resource('transitions', 'TransitionController')->except(['created', 'edit']); 

For a better view of the project architecture, below is a screenshot of the packages folder containing the package under development:

enter image description here

And finally, below is the composer.json declaring my package:

... "extra": { "laravel": { "providers": [ "AlvariumDigital\\WorkflowMakr\\WorkflowMakrServiceProvider" ] } }, "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/", "AlvariumDigital\\WorkflowMakr\\": "packages/AlvariumDigital/WorkflowMakr/src/" } }, ... 

When I execute the command php artisan route:list to view all my routes I got this error :

$> php artisan route:list Illuminate\Contracts\Container\BindingResolutionException Target class [AlvariumDigital\WorkflowMakr\Http\Controllers\ActionController] does not exist. at D:\Films\R_D\Laravel packages\workflow-makr\vendor\laravel\framework\src\Illuminate\Container\Container.php:832 828▕ 829▕ try { 830▕ $reflector = new ReflectionClass($concrete); 831▕ } catch (ReflectionException $e) { ➜ 832▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e); 833▕ } 834▕ 835▕ // If the type is not instantiable, the developer is attempting to resolve 836▕ // an abstract type such as an Interface or Abstract Class and there is 1 [internal]:0 Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route)) 2 D:\Films\R_D\Laravel packages\workflow-makr\vendor\laravel\framework\src\Illuminate\Container\Container.php:830 ReflectionException::("Class AlvariumDigital\WorkflowMakr\Http\Controllers\ActionController does not exist") 

EDIT

Below is the content of the ActionController file:

<?php namespace AlvariumDigital\WorkflowMakr\Http\Controllers; use AlvariumDigital\Models\Action; use AlvariumDigital\WorkflowMakr\Helpers\Constants; use Illuminate\Routing\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; class ActionController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\JsonResponse */ public function index() { $query = Action::query(); if (config('workflowmakr.pagination_size') == -1) { return response()->json($query->get(), 200); } return response()->json($query->paginate(config('workflowmakr.pagination_size')), 200); } // ... } 

EDIT 2

The content of the package composer.json file:

{ "name": "AlvariumDigital/WorkflowMakr", "description": "Generalize the management of your workflows", "type": "library", "license": "MIT", "authors": [ { "name": "Alvarium Digital", "email": "[email protected]", "homepage": "http://www.alvariumdigital.com", "role": "Corporate" }, { "name": "EL OUFIR Hatim", "email": "[email protected]", "homepage": "https://www.linkedin.com/in/eloufirhatim/", "role": "Developer" } ], "support": { "email": "[email protected]" }, "minimum-stability": "dev", "require": {} } 

Did I do something wrong or incomplete? You can ask for more details if needed.

Thanks

14
  • what namespace is defined in that php file for that controller? Commented Dec 14, 2020 at 16:26
  • @lagbox thanks for your reply, I just added the content of the file on my post. Commented Dec 14, 2020 at 16:28
  • 1
    btw, Route::resource without 'create' and 'edit' is the same as Route::apiResource Commented Dec 14, 2020 at 16:30
  • 1
    Did you run composer dump-autoload after adding the namespace (psr4) entry to composer.json? Commented Dec 14, 2020 at 16:32
  • 1
    Well you can have the psr4 entry in the composer.json of your package and then "repositories": [ {"type": "path", "url":"packages/AlvariumDigital/WorkflowMakr"}]in the composer.json of your app then run composer require AlvariumDigital/WorkflowMakr to require your package in the app. However as @lagbox has suggested your files should be in src if you are pointing the namespace to the src directory Commented Dec 14, 2020 at 16:49

1 Answer 1

3

You have structured this directory incorrectly. You have the PSR4 autoloading loading the src directory as the namespace. Your controllers are not in the src folder, only the Service Provider is in there. So to composer there are no files for it to find and autoload based on your PSR4 autoloading.

Sign up to request clarification or add additional context in comments.

2 Comments

THANK YOU, it works, I moved all my folders to be in the src/ folder, and it's working, thanks again
@ELOUFIRHatim just saw your comment on my answer for the controller not found issue ... well, glad this all worked out then :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.