掲題の通りです。
Php laravel を使用してwebページを表示したいのですが
bladeで@foreachなどを入れるとsyntax errorとなってしまいます。
ルーティングの設定、bladeの呼び出しは問題なく行えています。
エディタはVScodeを使用していますが、
blade自体も文字がハイライトされていないため、ただのテキストファイルとして認識されている状態なのでしょうか?
何が問題かご教示いただきたいです。。。
不足情報があればご指摘ください。
blade
1// App\Resource\views\user\index.blade.php 2@extends('layouts.layouts') 3@section('title', 'user一覧ページ') 4@section('content') 5 6@foreach($users as $user) 7ユーザー名:{{ $user->name }} 8@endforeach 9 10@endsection 11 12@section('footer') 13@endsection
layouts
1// App\Resource\views\layouts\layouts.blade.php 2 3<!DOCTYPE html> 4<html> 5 6<head> 7 <meta charset="utf-8"> 8 <meta http-equiv="X-UA-Compatible" content="IE=Edge"> 9 <meta name="csrf-token" content="{{ csrf_token() }}"> 10 <title>@yield('title')</title> 11 <style media="screen"> 12 body { 13 font-size: 16pt; 14 color: #999; 15 margin: 5px; 16 } 17 18 h1 { 19 font-size: 50pt; 20 text-align: right; 21 color: #f6f6f6; 22 margin: -20px 0 -30px 0; 23 letter-spacing: -4pt; 24 } 25 26 ul { 27 font-size: 12pt; 28 } 29 30 hr { 31 margin: 25px 100px; 32 border-top: 1px dashed #ddd; 33 } 34 35 .menutitle { 36 font-size: 14pt; 37 font-weight: bold; 38 margin: 0; 39 } 40 41 .content { 42 margin: 10px; 43 } 44 45 .footer { 46 text-align: right; 47 font-size: 10pt; 48 margin: 10px; 49 border-bottom: solid 1px #ccc; 50 color: #ccc; 51 } 52 </style> 53</head> 54 55<body> 56 <h1>@yield('title')</h1> 57 <ul> 58 <li>@show</li> 59 </ul> 60 <hr size="1"> 61 <div class="content"> 62 @yield('content') 63 </div> 64 <div class="footer"> 65 @yield('footer') 66 </div> 67</body> 68 69</html>
##追記
ご指摘いただいたのでエラーとコントローラーの処理を追記します。
発生しているエラー
syntax error, unexpected 'endforeach' (T_ENDFOREACH), expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)(View: /work/resources/views/users/index.blade.php)
controller
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use App\Models\User: 7 8class UserController extends Controller 9{ 10 11 public function index() 12 { 13 $users = User::get(); 14 return view('users.index')->with('users', $users); 15 } 16}
回答1件
あなたの回答
tips
プレビュー