https://teratail.com/questions/148471
と全く同じ部分で詰まっております。
コードの元はドットインストールです。
調べた結果、表題のエラーは配列でないものに対してforeachを回そうとした時のエラーの様です。
URLの方はキャストで解決したそうです。私の場合もそれで解決しそうではあるのですが、
外部的要因として変更したファイルが適応されていない気がします。
以下が問題のページです。
php
1@extends('layouts.default') 2 3@section('title', $post->title) 4 5@section('content') 6<h1> 7 <a href="{{ url('/') }}" class="header-menu">Back</a> 8 {{ $post->title }} 9</h1> 10<p>{!! nl2br(e($post->body)) !!}</p> 11 12<h2>Comments</h2> 13<ul> 14 @forelse ($post->comments as $comment) 15 <li> 16 {{ $comment->body }} 17 </li> 18 @empty 19 <li>No comments yet</li> 20 @endforelse 21</ul> 22@endsection
これはその問題のあるページに飛ぶ前のページです。
@extends('layouts.default') @section('title', 'Blog Posts') @section('content') <h1> <a href="{{ url('/posts/create') }}" class="header-menu">New Post</a> Blog Posts </h1> <ul> <h2>What's happning?????</h2><!--このh2タグが読み込まれていない--> @forelse ($posts as $post) <li> <a href="{{ action('PostsController@show', $post) }}">{{ $post->title }}</a> <a href="{{ action('PostsController@edit', $post) }}" class="edit">[Edit]</a> <a href="#" class="del" data-id="{{ $post->id }}">[x]</a> <form method="post" action="{{ url('/posts', $post->id) }}" id="form_{{ $post->id }}"> {{ csrf_field() }} {{ method_field('delete') }} </form> </li> @empty <li>No posts yet</li> @endforelse </ul> <script src="/js/main.js"></script> @endsection
上記の様にh2タグを入れましたが、ブラウザに表示されません。(白紙しても表示されます。)
転送ツールの問題かと思ったのですが以下のphpファイルを白紙にしたら遷移しないので繋がってはいる様です。
php
1<?php 2 3/* 4|-------------------------------------------------------------------------- 5| Web Routes 6|-------------------------------------------------------------------------- 7| 8| Here is where you can register web routes for your application. These 9| routes are loaded by the RouteServiceProvider within a group which 10| contains the "web" middleware group. Now create something great! 11| 12*/ 13 14Route::get('/', 'PostsController@index'); 15// Route::get('/posts/{id}', 'PostsController@show'); 16Route::get('/posts/{post}', 'PostsController@show')->where('post', '[0-9]+'); 17Route::get('/posts/create', 'PostsController@create'); 18Route::post('/posts', 'PostsController@store'); 19Route::get('/posts/{post}/edit', 'PostsController@edit'); 20Route::patch('/posts/{post}', 'PostsController@update'); 21Route::delete('/posts/{post}', 'PostsController@destroy'); 22
ただ上記のweb.phpのみ変更を加えるとpcの画面に転送ツールから変更しましたの様なメッセージ表示されます。お助けお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。