Error in ReflectionException cannot be resolved when configuring HomeMiddleware in Ravel.

Asked 2 years ago, Updated 2 years ago, 92 views

I thought I copied the code of the book completely for Ravel's study, but the following error came out.
I would appreciate it if you could let me know.

Error Contents

ReflectionException
Class App\Http\Controllers\HomeMiddleware does not exist

Class App\Http\Controllers\HomeMiddleware does not exist/Users/horikawatokiya/Diagnosis/diagnosis/vendor/larvel/framework/src/Illuminate/Container/Container.php#729
    ReflectionException

Files That May Be Relevant

web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider with a group which
| contains the "web" middleware group. Now create something great!
|
*/
// useApp\Http\Middleware\HomeMiddleware;

Route::get('home','HomeMiddleware@index') ->middleware(HomeMiddleware::class);
Route::post('home','HomeController@post');

HomeController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;

class HomeController extensions Controller {

    public function index(Request$request){
        echo "test";
        return view('home.index', ['data'=>$request->data]);
    }

    public function post(Request$request){
        return view('home.index', ['msg'=>$request->msg]);
    }

}

index.blade.php

@extends('layouts.diagnosis')

@section('title', 'Index')

@section('menubar')
    @parent
    index page
@endsection

@section('content')
    <p> This is the content of the body.</p>
    <table>
    @foreach($data as$item)
    <tr>
        <th>
            {{$item['name']}}
        </th>
        <td>
            {{$item['mail']}}
        </td>
    </tr>
    </table>
@endsection

HomeMiddleware.php

<?php

namespace App\Http\Middleware;

use Close;

classHomeMiddleware{
    /**
     * Handle an incoming request.
     *
     * @param\Illuminate\Http\Request$request
     * @param\Closure$next
     * @param string | null$guard
     * @return mixed
     */
    public function handle($request,Closure$next){
        $data=[
            ['name'=>'taro', 'mail'=>'taro@mail',
            ['name'=>'hanako', 'mail'=>'hanako@mail',
            ['name'=>'sachico', 'mail'=>'sachico@mail',
        ];
        $request->merge(['data'=>$data]);
        return$next($request);
    }
}

    @section('footer')
    copyright 2017 tuyano.
    @endsection

php laravel

2022-09-30 21:33

1 Answers

This is

//useApp\Http\Middleware\HomeMiddleware;

Route::get('home','HomeMiddleware@index') ->middleware(HomeMiddleware::class);

↓ I think this will work.

useApp\Http\Middleware\HomeMiddleware;

Route::get('home', 'HomeController@index') - > middleware(HomeMiddleware::class);


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.