2
votes

Background

I know what I'm trying to do sounds a bit wrong but I do have my reasons. Basically I have a central core app that's a default laravel app with a few tweaks and boilerplate code, I have then developed a series of packages that can be used to extend the app through composer. These packages are not meant to function without the core framework so a dependency upon it is fully expected.

What I want to do

What I would like to do is have a BaseController in my core app and have the various controllers in my package extend this BaseController to provide universal functionality throughout the various module packages.

I was expecting to be able to place the base controller in app/controllers/BaseController.php and then extend it from my package using:

class PackageController extends \BaseController{}

Unfortunately when I do this it still looks within the package (currently workbenched) for the controller and I get the error:

include(/var/www/l4core.dev/workbench/myvendor/mypackage/src/controllers/BaseController.php): failed to open stream: No such file or directory

Can anyone tell me what I'm doing wrong here. I am looking for a solution which allows me to easily move my packages between vendor dir and workbench for development. Any help greatly appreciated

Update

The previously mentioned error message appears to have been due to an include in my packages /vendor/composer/classloader.php - I have now deleted the vendor directory and done a fresh composer install. This has not solved the problem but it has at least shifted it as I now get the following error message:

Class 'BaseController' not found

My Packages composer.json

{
    "name": "modules/sesame",
    "description": "",
    "authors": [
        {
            "name": "any",
            "email": ""
        }
    ],
    "require": {
        "php": ">=5.4.0",
        "illuminate/support": "4.0.x",
        "zizaco/confide": "dev-master",
        "zizaco/entrust": "dev-master",
        "conarwelsh/mustache-l4": "dev-master"
    },
    "autoload": {
        "classmap": [
            "src/controllers",
            "src/models",
            "src/migrations",
            "src/seeds"
        ],
        "psr-0": {
            "Modules\\Sesame": "src/"
        }
    },
    "minimum-stability": "dev"
}
1
It is really strange that you have an "include" error, usually it is a "Class not found". Can you give us a snippet of your package composer.json file?FR6
@FR6 Thanks for giving it some attention - I have added the composer.json for the package.SwiftD
You say, you put BaseController in app directory => app/BaseController.php. I am not sure autoloading works just from app directory, try to place controller into app/controllers or any other folder included in autoloading.Andreyco
Sorry, no it's not, that was a typo, the controller is in app/controllersSwiftD
I have updated my question as I now have a standard class not found message after a fresh composer installSwiftD

1 Answers

2
votes

Be sure to execute:

php artisan dump-autoload

And verify that your class BaseController is in /vendor/composer/autoload_classmap.php.

OR like the OP stated, removing the vendor directory and running composer install again could sometimes solve the problem.