Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Laravel 5 - BadMethodCallException in ServiceProvider.php line 111: Call to undefined method [package] #62

Closed
BrunoQuaresma opened this issue Jan 3, 2015 · 10 comments

Comments

@BrunoQuaresma
Copy link

breadcrumbs.php

Breadcrumbs::register('home', function($breadcrumbs) {
    $breadcrumbs->push('Home', '/');
});

my view

//...
{!! Breadcrumbs::render('home') !!}
//...

Error

BadMethodCallException in ServiceProvider.php line 111:
Call to undefined method [package]

in ServiceProvider.php line 111
at ServiceProvider->__call('package', array('davejamesmiller/laravel-breadcrumbs')) in ServiceProvider.php line 50
at ServiceProvider->package('davejamesmiller/laravel-breadcrumbs') in ServiceProvider.php line 50
at ServiceProvider->boot()
at call_user_func_array(array(object(ServiceProvider), 'boot'), array()) in Container.php line 530
at Container->call(array(object(ServiceProvider), 'boot')) in Application.php line 564
at Application->bootProvider(object(ServiceProvider)) in Application.php line 377
at Application->register(object(ServiceProvider)) in Application.php line 476
at Application->registerDeferredProvider('DaveJamesMiller\Breadcrumbs\ServiceProvider', 'breadcrumbs') in Application.php line 458
at Application->loadDeferredProvider('breadcrumbs') in Application.php line 502
at Application->make('breadcrumbs') in Container.php line 1191
at Container->offsetGet('breadcrumbs') in Facade.php line 148
at Facade::resolveFacadeInstance('breadcrumbs') in Facade.php line 118
at Facade::getFacadeRoot() in Facade.php line 202
at Facade::__callStatic('render', array('home')) in c51afa214851930e34b35b9f120f93e7 line 9
at Facade::render('home') in c51afa214851930e34b35b9f120f93e7 line 9
at include('/home/vagrant/Code/ead/storage/framework/views/c51afa214851930e34b35b9f120f93e7') in PhpEngine.php line 37
at PhpEngine->evaluatePath('/home/vagrant/Code/ead/storage/framework/views/c51afa214851930e34b35b9f120f93e7', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'obLevel' => '1', 'course' => object(Course), 'lesson' => object(Lesson), 'files' => object(Collection), 'header_title' => 'O Cliente', 'header_subtitle' => 'Entendendo O Cliente', 'edit' => '/courses/4/lessons/5/edit', 'delete' => 'courses/4/lessons/5')) in CompilerEngine.php line 57
at CompilerEngine->get('/home/vagrant/Code/ead/resources/templates/courses/pageheader-edit.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'obLevel' => '1', 'course' => object(Course), 'lesson' => object(Lesson), 'files' => object(Collection), 'header_title' => 'O Cliente', 'header_subtitle' => 'Entendendo O Cliente', 'edit' => '/courses/4/lessons/5/edit', 'delete' => 'courses/4/lessons/5')) in View.php line 136
at View->getContents() in View.php line 104
at View->renderContents() in View.php line 78
at View->render() in 04a3a5d2f2451fa4289af95c613de8f2 line 10
at include('/home/vagrant/Code/ead/storage/framework/views/04a3a5d2f2451fa4289af95c613de8f2') in PhpEngine.php line 37
at PhpEngine->evaluatePath('/home/vagrant/Code/ead/storage/framework/views/04a3a5d2f2451fa4289af95c613de8f2', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'course' => object(Course), 'lesson' => object(Lesson), 'files' => object(Collection))) in CompilerEngine.php line 57
at CompilerEngine->get('/home/vagrant/Code/ead/resources/templates/lessons/show.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'course' => object(Course), 'lesson' => object(Lesson), 'files' => object(Collection))) in View.php line 136
at View->getContents() in View.php line 104
at View->renderContents() in View.php line 78
at View->render() in Response.php line 44
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1171
at Router->prepareResponse(object(Request), object(View)) in Router.php line 649
at Router->dispatchToRoute(object(Request)) in Router.php line 604
at Router->dispatch(object(Request)) in Kernel.php line 155
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 53
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 108
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 83
at Kernel->handle(object(Request)) in index.php line 53
@d13r
Copy link
Owner

d13r commented Jan 3, 2015

I assume this is in Laravel 5 (dev-master version) - it's related to this commit but I don't yet know what the correct fix for it is so I'm planning to leave it until nearer the release date unless anyone knows the correct solution.

@d13r d13r changed the title BadMethodCallException in ServiceProvider.php line 111: Call to undefined method [package] Laravel 5 - BadMethodCallException in ServiceProvider.php line 111: Call to undefined method [package] Jan 3, 2015
@mauserrifle
Copy link

Could fix using the info in the comments commit there. Anyway I am new to Laravel and find what the package method was used for very weird if configs could just be cascaded.

I fixed it by creating my own provider as temporary solution using config/breadcrumb.php as the config file hardcoded:

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider as BaseServiceProvider;

use DaveJamesMiller\Breadcrumbs\Manager;

class BreadcrumbsServiceProvider extends BaseServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return array('breadcrumbs');
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app['breadcrumbs'] = $this->app->share(function($app)
        {
            $breadcrumbs = new Manager($app['view'], $app['router']);

            $breadcrumbs->setView($app['config']['breadcrumbs.view']);

            return $breadcrumbs;
        });
    }

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        // Register the package so the default view can be loaded
        // DISABLED AND CHANGED CONFIG FILE ABOVE
        // $this->package('davejamesmiller/laravel-breadcrumbs');

        // Load the app breadcrumbs if they're in app/Http/breadcrumbs.php (Laravel 5.x)
        if (file_exists($file = $this->app['path'].'/Http/breadcrumbs.php'))
            require $file;

        // Load the app breadcrumbs if they're in app/breadcrumbs.php (Laravel 4.x)
        elseif (file_exists($file = $this->app['path'].'/breadcrumbs.php'))
            require $file;
    }
}

@d13r
Copy link
Owner

d13r commented Jan 14, 2015

FYI, you can probably simplify that by extending my class instead of re-implementing the whole thing (untested):

<?php namespace App\Providers;

use DaveJamesMiller\Breadcrumbs\ServiceProvider as BaseServiceProvider;

class BreadcrumbsServiceProvider extends BaseServiceProvider
{
    protected function package() {}
}

Thanks for pointing out the updated comments in the commit above, but it still looks like a workaround rather than a solution so I'm going to wait to see what the official word is when the documentation is finally updated before I spend more time on it.

@christian-thomas
Copy link
Contributor

For anyone that wants to use this in L5 at the moment... I've forked the repo, which is now compatible with L5's new package structure now that it's documented.

@d13r
Copy link
Owner

d13r commented Jan 27, 2015

Do you have a URL for your fork? I couldn't find it.

I'll try to read up on the changes soon and release an update, but probably not this week. I'm thinking about making a new major release at the same time - dropping support for 4.x (rather than trying to maintain compatibility in a single branch) and taking advantage of some of the L5 changes (like improved service provider support).

@christian-thomas
Copy link
Contributor

Ah yep, I should've linked that. It's https://github.com/industrious-mouse/laravel-breadcrumbs/tree/develop

Yeah I would imagine that's the route a lot of package developers are going to take, it's quite a big breaking change removing the l4 package functionality. Just drop l4 into a separate branch and I guess everyone's a winner.

@d13r
Copy link
Owner

d13r commented Jan 27, 2015

Your changes look good, thanks for taking the time to do that. I'll try to test & merge it as soon as I get a free weekend.

@christian-thomas
Copy link
Contributor

No problem - Thanks for the package!

I think the only area which might need changing, is the config file location in my fork is set as config/vendor/breadcrumbs.php, where as I think the tendency is that people are just putting the config file in the root config directory. (Which I'm not really a fan of)

@d13r
Copy link
Owner

d13r commented Feb 8, 2015

Released in 3.0.0 (along with a major internal refactoring, much better unit test coverage and brand new documentation).

@d13r d13r closed this as completed Feb 8, 2015
@christian-thomas
Copy link
Contributor

Sweeeet, thanks! 👌

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants