1

Class App\Http\Controllers\HomeController does not exist

HomeController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post;

class HomeController extends Controller
{
    public function index()
    {
        $posts = Post::paginate(10);
        return view ('pages.index', ['posts' => $posts]);
    }

    public function show($slug)
    {
        $post = Post::where('slug', $slug)->firstOrFail();

        return view ('pages.show', compact('post')); 
    }
}

web.php

Route::get('/', 'HomeController@index');
Route::get('/post/{slug}', 'HomeController@show')->name('post.show');
Route::group(['prefix'=>'admin','namespace'=>'Admin'], function(){
    Route::get('/', 'DashboardController@index');
    Route::resource('/categories', 'CategoriesController');
    Route::resource('/tags', 'TagsController');
    Route::resource('/users', 'UsersController');
    Route::resource('/posts', 'PostsController');
});

At the beginning a new authorization controller appeared, I turned off the KG and removed

Priyanka khullar
  • 509
  • 1
  • 5
  • 25
ran4
  • 29
  • 3

2 Answers2

-1

Run this command to clear all compiled files:

php artisan clear-compiled

See more as this commands here:

https://laravel.com/docs/5.8/artisan

Hope this helps!

Rafael Laurindo
  • 474
  • 2
  • 7
-1

In some cases adding the controller directory resolves this issue. Please check the controller directory and make changes according to that.

Normally it is App\Http\Controllers if so, then you can try with changing the route code to the following:

Route::get('/', 'App\Http\Controllers\HomeController@index');
Route::get('/post/{slug}', 'App\Http\Controllers\HomeController@show')->name('post.show');

check your controller directory.

Hriju
  • 728
  • 1
  • 16
  • 27