@Vova135798

Как исправить ошибку Target class [...] does not exist?

Почему мне выдает ошибку Target class [TestController] does not exist?
Файл TestController.php находится в app\Http\Controllers\TestController.php

web.php

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return '!!!';
});

Route::get('/products/{title}', function ($title) {
    return 'Страница продукта' . $title;
});

Route::get('/show', 'TestController@show');


TestController.php

<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    public function show()
    {
        return 'TestController';
    }
}
?>
  • Вопрос задан
  • 280 просмотров
Решения вопроса 2
@kandrash
Кратко о себе
Сейчас принято писать
Route::get('/show', [TestController::class, 'show']);

И самая зачуханая IDE подскажет, что такого класса нет, пиши неймспейс полностью
Ответ написан
Комментировать
alexey-m-ukolov
@alexey-m-ukolov Куратор тега Laravel
If you would like to continue using the original auto-prefixed controller routing, you can simply set the value of the $namespace property within your RouteServiceProvider and update the route registrations within the boot method to use the $namespace property


https://laravel.com/docs/8.x/upgrade#automatic-con...
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы