我在 laravel 中使用 tinker 函数,但是当我输入以下内容时:
>>>user App\PostController;
>>>PostController::get();
我收到以下错误:
PHP Fatal error: Class 'App/PostController' not found in Psy Shell code on line 1
我该如何解决?
您可以使用以下内容:
$controller = app()->make(App\Http\Controllers\PostController::class);
app()->call([$controller, 'get']);
如果要将参数传递给方法:
$controller = app()->make(App\Http\Controllers\PostController::class);
app()->call([$controller, 'get'], ['test' => 123]);
控制器位于 App\Http\Controllers 命名空间下use App\Http\Controllers\PostController