My application always gives me this error:
Illuminate \ Contracts \ Container \ BindingResolutionException PHP 8.1.10 10.28.0 Target class [App\Http\Middleware\TrustHosts] does not exist.
web.php
Route::get('/', [ListingController::class, 'index']);
Single Listing
Route::get('/listings/{listing}', [ListingController::class, 'show']);
app/http/kernel.php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
// */
protected $middleware = [
\App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
}
I tried installing composer dump-autoload through the terminal. Also, i tried adding middleware to my route:
Route::get('/', [ListingController::class, 'index'])->middleware('TrustHosts');
// Single Listing
Route::get('/listings/{listing}', [ListingController::class, 'show'])->middleware('TrustHosts');
I tried checking for any typo errors, but all in vain. Someone should help, please. Thank you.`