Class 'App\Http\Controllers\Controller' 在 Laravel 8 中找不到

Class 'App\Http\Controllers\Controller' not found in Laravel 8

控制器

namespace App\Http\Controllers;

use App\Models\Article;
use Illuminate\Http\Request;


class ArticlesController extends Controller
{
    public function show($id)
    {
        $article = Article::find($id);

        return view('articles.show', ['article' => $article]);
    }
}

路线

use Illuminate\Support\Facades\Route;

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

Route::get('/about', function () {
    return view('about', [
        'articles' => App\Models\Article::take(3)->latest()->get()
    ]);
});

Route::get('/articles/{article}',
    'App\Http\Controllers\ArticlesController@show');

show.blade.php

@extends ('layout')
@section ('content')
    <div id="wrapper">
        <div id="page" class="container">
            <div id="content">
                <div class="title">
                    <h3>{{ $article->title }}</h3>
                    <p>
                        <img src="/images/banner.jpg" alt=""
                             class="image image-full"/>
                    </p>
                    <p>{{ $article->body }}</p>
                </div>
            </div>
@endsection

错误

Class 'App\Http\Controllers\Controller' not found http://localhost:8000/articles/2

我不确定我哪里出错了。我查看了 Laravel 8 中 routes/controllers 的文档,看起来我所拥有的应该可以工作。

看来你的扩展控制器有问题。

请检查 Controller.php 是否存在于 App\Http\Controllers 中。

所有与您相同的控制器 (ArticlesController) 从 Controller 扩展