Search code examples
phplaravel-routinglaravel-8laravel-controller

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


Controller

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]);
    }
}

Routes

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

Error

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

I am not sure where I am going wrong. I have looked at the documentation for routes/controllers in Laravel 8, and it looks like what I have should be working.


Solution

  • It seems there is something wrong with your extended controller.

    please check Controller.php existed in App\Http\Controllers or not.

    All controller same as yours (ArticlesController) extended from Controller