Question

I'm trying to develop a package, so I've followed this tutorial until Creating a Facade section because I don't need a facade.

The problem is:

/app/routes.php
Route::get('test', 'Aristona\Installer\Installer@install');

throws an exception: Call to undefined method Aristona\Installer\Installer::callAction()

My Installer.php is like this:

workbench/aristona/installer/src/Aristona/Installer/Installer.php
<?php namespace Aristona\Installer;

class Installer
{
    public static function install()
    {
        return "Hello";
    }
}

The class is loading. I've added it to my service providers list. Also I can confirm it is loading by adding one more install method, because PHP throws a fatal error about redeclaring same method twice.

I've tried different combinations on my method prefixes (e.g without static) Doesn't solve.

Anyone know what am I doing wrong?

Was it helpful?

Solution

Your getting an error because you're trying to use routing to controller where none exists. To be more specific, Laravel is trying to perform this method from it's core Controller class:

/**
 * Execute an action on the controller.
 *
 * @param string  $method
 * @param array   $parameters
 * @return \Symfony\Component\HttpFoundation\Response
 */
public function callAction($method, $parameters)
{
    $this->setupLayout();

    $response = call_user_func_array(array($this, $method), $parameters);

    // If no response is returned from the controller action and a layout is being
    // used we will assume we want to just return the layout view as any nested
    // views were probably bound on this view during this controller actions.
    if (is_null($response) && ! is_null($this->layout))
    {
        $response = $this->layout;
    }

    return $response;
}

So unless the class you're specifying in Route::get() is extending either BaseController or Controller, this exception will be thrown. If you tested the same method inside a closure, it would work.

More about Laravel controller routing can be found here.

To fix this, you should either add a controller to your package or use the Installer class inside another controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top