0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[解決済み]syntax error, unexpected token "endif", expecting end of file

Last updated at Posted at 2024-07-04

解決しました

環境
PHP 8.3.7
Laravel 11.6.0

問題

どこにも@endifが欠けていないのにsyntax error, unexpected token "endif", expecting end of fileというエラーが出る。

profile-post.blade.php
<x-profile :sharedData="$sharedData" doctitle="{{$sharedData["username"]}}'s Profile">
  <div class="list-group">
    @foreach($posts as $post)
    <a href="/post/{{$post->id}}" class="list-group-item list-group-item-action">
      <img class="avatar-tiny" src="{{$post->user->avatar}}" />
      <strong>{{$post->title}}</strong> on {{$post->created_at->format("Y/n/j")}}
    </a>
-   @endforeach
  </div>
</x-profile>

試み

  • GPTで全てのファイルを参照し@endifが欠けていないか確認
  • 念の為目視でも確認
  • 誤字脱字確認
  • Laravelキャッシュクリア、Laravelの再起動
  • @isset@foreachなども欠けていないか確認
  • こちらの記事に書いてあったような構文チェック

多分…

ページタイトルを自動で変えるようにissetを使っていたところ、個々のポストでは正常に動作したのだがプロフィールページを構ったらこのエラーが出てしまった。
なのでおそらくprofile.blade.phpもしくはprofile-post.blade.phpに問題があるんだと思う。
もっと頭を柔らかく考えれば切り分けができて特定もできるんだろうが、今は難しい…。

ブログ

コードブロックの強調したい箇所やエラー箇所などに帯をつけるやつ、やってみたかったからできて嬉しい。

解決(2024/07/05)

シングルクォーテーションとダブルクォーテーションのミスだった。

<x-profile :sharedData="$sharedData" doctitle="{{$sharedData['username']}}'s Profile">
元は"username"(ダブル)としていたが、教材と見比べて'username'(シングル)にしたらエラー解消された。
なおそこ以外のクォーテーションは構っていない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?