2

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
  • 479
  • 1
  • 5
  • 24
ran4
  • 31
  • 2

3 Answers3

0

Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications. Here is full explanation: https://www.youtube.com/watch?v=Q1ynDMC8UGg

  • php artisan config:clear
  • php artisan cache:clear
  • composer dump-autoload
  • php artisan view:clear
  • php artisan route:clear

Please have a look at this thread: https://stackoverflow.com/a/43041479/6935763

Abhay Maurya
  • 10,668
  • 6
  • 42
  • 58
0

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
  • 476
  • 2
  • 7
0

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
  • 650
  • 1
  • 16
  • 26