0

I have a fresh instance of Laravel 9. I am migrating all my controllers from an old Laravel 8 application. My problem is that the app cannot see the controller.

Target class [AdminToolsController] does not exist.

web.php

Route::get('/php', 'AdminToolsController@php');

Controller

public function php() 
{
    $laravel = app();
    echo "Your Laravel version is ".$laravel::VERSION;
    echo phpinfo();
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Peter
  • 2,634
  • 7
  • 32
  • 46

1 Answers1

3

The syntax for routes has been Route::get(uri, [controller, action]) for some time now. It's not a laravel 9 thing

use App\Http\Controllers\AdminToolsController;

Route::get('/php', [AdminToolsController::class, 'php']);

or

Route::get('/php', [\App\Http\Controllers\AdminToolsController::class, 'php']);
IGP
  • 14,160
  • 4
  • 26
  • 43
  • came here fresh outta laravel 5.5 and boy oh boy...............looks like I got a world of shock coming up............ – Mash tan Dec 15 '22 at 10:31
  • 1
    Aside from some directories changing place and this syntax for actions, it's mostly the same. If you want a full comprehensive list of what changed, I suggest you read the upgrade guides in the documentation. https://laravel.com/docs/5.6/upgrade, then 5.7, 5.8, 6.x, 7.x, 8.x, 9.x and 10.x is going to come out in a couple of months is the schedule stays the same. – IGP Dec 15 '22 at 15:10
  • i dont understand why they had to force this ugly syntax – Tadas V. Apr 26 '23 at 14:03
  • @Tadas V. The reason is mostly static analysis and code completion and less "string programming". If you run `php artisan route:cache` and inspect the generated file at (`/your-project/bootstrap/cache/routes-v7.php` you'll see it still seems to use the old syntax in some places. – IGP Apr 26 '23 at 18:06
  • Another possible syntax that could become popular is using [PHP 8.1's first class callable syntax](https://www.php.net/manual/en/functions.first_class_callable_syntax.php). I personally wouldn't yet, but you ***can*** do stuff like `Route::get('/php', app(AdminToolsController::class)->php(...));` – IGP Apr 26 '23 at 18:11