laravelでのミドルウェアですが、現在書籍で勉強中なのですがエラーが出て理解が出来ていないのでご教授いただけないでしょうか?
resources\views\hello\index.blade.php
php
1@section('content') 2 <p>ここが本文のコンテンツです。</p> 3 <table> 4 @foreach($data as $item) 5 <tr><th>{{$item['name']}}</th><td>{{$item['mail']}}</td></tr> 6 @endforeach 7 </table> 8@endsection
app\Http\Middleware\HelloMiddleware.php
php
1<?php 2namespace App\Http\Middleware; 3use Closure; 4class HelloMiddleware 5{ 6 public function handle($request, Closure $next) 7 { 8 $data = [ 9 ['name'=>'taro', 'mail'=>'taro@yamada'], 10 ['name'=>'hanako', 'mail'=>'hanako@flower'], 11 ['name'=>'sachiko', 'mail'=>'sachico@happy'], 12 ]; 13 $request->merge(['data'=>$data]); 14 return $next($request); 15 } 16} 17
routes\web.php
php
1<?php 2Route::get('/', function () { 3 return view('welcome'); 4}); 5// use App\Http\Middleware\HelloMiddleware; を追記 6Route::get('hello', 'HelloController@index')->middleware(HelloMiddleware::class); 7Route::post('hello','HelloController@post');
app\Http\Controllers\HelloController.php
php
1<?php 2namespace App\Http\Controllers; 3use Illuminate\Http\Request; 4use Illuminate\Http\Response; 5class HelloController extends Controller 6{ 7public function index(Request $request) 8{ 9 return view('hello.index', ['data'=>$request->data]); 10} 11}
app\Http\Kernel.php
php
1 protected $routeMiddleware = [ 2 'auth' => \App\Http\Middleware\Authenticate::class, 3 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 4 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 5 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 6 'can' => \Illuminate\Auth\Middleware\Authorize::class, 7 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 8 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 9 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 10 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 11 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 12 'hello' => \App\Http\Middleware\HelloMiddleware::class, 13 ];
変更したところをすべて記載させていただきました。
初心者で基本的な事だと思いますが、何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/09 17:26