Accessing package controllers in Laravel 4

前端 未结 3 2017
滥情空心
滥情空心 2020-12-15 10:48

I have created a package following the \"Creating a Package\" instructions in the Laravel 4 documentation. After creating the package I have created a \"controllers\" folder

相关标签:
3条回答
  • 2020-12-15 10:58

    You may try edit your Vendor/Package/composer.json and insert the controllers dir to autoload/classmap:

    ....
    "autoload": {
        "classmap": [
            "src/migrations",
            "src/controllers",
            "src/models"
        ],
        "psr-0": {
            "Package\\Controller": "src/"
        }
    }
    ....
    

    After that, open your terminal and from your package root dir do a composer dump-autoload

    Works for me...

    0 讨论(0)
  • 2020-12-15 11:06

    have a look into this git article might be of help https://github.com/jaiwalker/setup-laravel4-package

    0 讨论(0)
  • 2020-12-15 11:13

    The mistake was including the controllers path in the route. I had the following:

    Route::get('/package', 'Vendor\Package\Controllers\HomeController@showWelcome');
    

    The correct usage is:

    Route::get('/package', 'Vendor\Package\HomeController@showWelcome');
    

    With the namespace included in the controller:

    namespace Vendor\Package;
    

    Controller should extend illuminate:

    \Illuminate\Routing\Controllers\Controller
    

    Still can't use the package name (eg: Package::HomeController@showWelcome), but I can using the namespace. yay.

    Problem solved.

    0 讨论(0)
提交回复
热议问题