0
votes

web.php seems to be okay however, BindingResolutionException Target class [App\Http\Controllers\App\Stack\Http\Controllers\HomeController] does not exist.

error happens.

Where should fix it?

web.php

Route::get('/home', 'App\Stack\Http\Controllers\HomeController@index')->name('home');

HomeController.php

<?php

namespace App\Stack\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Stack\Http\Middleware\SetDefaultLayoutForUrls;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware(['auth', SetDefaultLayoutForUrls::class]);
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('home');
    }

the file is located at {thisProject}/app/Http/Controllers

2

2 Answers

0
votes

In web.php you say that the controller is at :

App\Stack\Http\Controllers\HomeController

but in your comment you say that the controller is at

{thisProject}/app/Http/Controllers
0
votes

Try changing your homecontroller namespace to:

namespace App\Stack\Http\Controllers;

And your route to:

Route::get('/home', 'App\Http\Controllers\HomeController@index')->name('home');