-1

Im using the tinker function in laravel but when i type the following in:

>>>user App\PostController;
>>>PostController::get();

I get the following error:

PHP Fatal error:  Class 'App/PostController' not found in Psy Shell code on line 1

How do i fix this?

Gino Sesia
  • 383
  • 2
  • 4
  • 14

2 Answers2

3

You can use the following:

$controller = app()->make(App\Http\Controllers\PostController::class);

app()->call([$controller, 'get']);

If you want to pass arguments to the method:

$controller = app()->make(App\Http\Controllers\PostController::class);

app()->call([$controller, 'get'], ['test' => 123]);
Remul
  • 7,874
  • 1
  • 13
  • 30
1

Controllers are under App\Http\Controllers namespace try use App\Http\Controllers\PostController

AxissXs
  • 121
  • 9
  • @GinoSesia did you double check class name in the file, it's namespace, etc? have you tried using the class and it's method in a test route and see if it will work? sometimes doing composer dump-autoload might help.try that and let me know if it helps – AxissXs Nov 04 '20 at 18:11