Laravel app::call('SomeController@method') not working

时间:2018-01-03 09:57:54

标签: php laravel laravel-5

I want to be able to call a method inside a controller in the following manner:

App::call('SomeController@method');

I figured it happens like this when defining a route:

Route::get('/route', 'SomeController@method');

So maybe there's an underlying mechanism I can use more generally in my code on other places in the project, turns out there is (App::call()).

The problem I'm running into is that this generates an error:

ReflectionException (-1)
Class SomeController does not exist

## \vendor\laravel\framework\src\Illuminate\Container\Container.php

public function build($concrete)
{
    // If the concrete type is actually a Closure, we will just execute it and
    // hand back the results of the functions, which allows functions to be
    // used as resolvers for more fine-tuned resolution of these objects.
    if ($concrete instanceof Closure) {
        return $concrete($this, $this->getLastParameterOverride());
    }

    $reflector = new ReflectionClass($concrete);

    // If the type is not instantiable, the developer is attempting to resolve
    // an abstract type such as an Interface of Abstract Class and there is
    // no binding registered for the abstractions so we need to bail out.
    if (! $reflector->isInstantiable()) {
        return $this->notInstantiable($concrete);
    }

    $this->buildStack[] = $concrete;

    $constructor = $reflector->getConstructor();

I'm pretty sure I must include some stuff somewhere but since Laravel is pretty big I'm asking this community.

2 个答案:

答案 0 :(得分:1)

尝试提供完整的命名空间,如:

plt.imshow(np.squeeze(s))

答案 1 :(得分:0)

您可以使用app()帮助程序调用该方法。语法为app($fullControllerClassName)->methodYouWantToCall()

app('App\Http\Controllers\SomeController')->method();