前提・実現したいこと
OS:Windows7
PHP7.2.6
Laravel5.6.26
https://beiznotes.org/making-task-list-with-laravel55-2/
こちらのサイトを参考に、Laravelでの簡単なプロジェクト作成・DB利用を行っています。
タスクの表示をしたく、レイアウトの@yield('content')に
ビューファイルの@section('content')~@endsectionを読み込むところでエラーが発生しています。
発生している問題・エラーメッセージ
[2018-07-04 00:32:37] local.ERROR: Use of undefined constant ‘content’ - assumed '‘content’' (this will throw an Error in a future version of PHP) (View: C:\pleiades_php\xampp\htdocs\quickstart\resources\views\tasks.blade.php) {"exception":"[object] (ErrorException(code: 0): Use of undefined constant ‘content’ - assumed '‘content’' (this will throw an Error in a future version of PHP) (View: C:\pleiades_php\xampp\htdocs\quickstart\ esources\views\tasks.blade.php) at C:\pleiades_php\xampp\htdocs\quickstart\storage\framework\views\0992f40a2b6f6825676bd23096439b1ac91ffd33.php:2, ErrorException(code: 0): Use of undefined constant ‘content’ - assumed '‘content’' (this will throw an Error in a future version of PHP) at C:\pleiades_php\xampp\htdocs\quickstart\storage\framework\views\0992f40a2b6f6825676bd23096439b1ac91ffd33.php:2) [stacktrace] スタックトレースが長すぎて文字数オーバーな為、省略しています。 "}
該当のソースコード
resources/views/layouts/app.blade.php
PHP
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <title>Laravel Quickstart - Basic</title> 5 <!-- Fonts --> 6 <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel='stylesheet' type='text/css' /> 7 <!-- Styles --> 8 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> 9 </head> 10 <body> 11 <!-- ナビゲーションバー (bootstrap利用)--> 12 <nav class="navbar navbar-default"> 13 <div class="container"> 14 <div class="navbar-header"> 15 <a class="navbar-brand" href="{{ url('/') }}"> 16 TaskList 17 </a> 18 </div> 19 </div> 20 </nav> 21 <!-- Bladeのディレクティブ。この部分に小ページの内容が挿入される。 --> 22 @yield('content') 23 <!-- JavaScripts --> 24 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 25 </body> 26</html>
resources/views/tasks.blade.php
PHP
1@extends('layouts.app')<!-- 親ページ layouts/app.blade.phpが呼ばれる。 --> 2@section('content')<!-- レイアウトの@yield(‘content’)に、@section~@endsectionが入る。 --> 3<div class="container"> 4 <div class="col-sm-offset-2 col-sm-8"> 5 <!-- TODO: Current Tasks --> 6 @if (count($tasks) > 0) <!-- web.phpのルートで定義したtasks --> 7 <div class="panel panel-default"> 8 <div class="panel-heading"> 9 Current Tasks 10 </div> 11 <div class="panel-body"> 12 <table class="table table-striped task-table"> 13 <thead> 14 <th>Task</th> 15 <th> </th> 16 </thead> 17 <tbody> 18 @foreach($tasks as $task) 19 <tr> 20 <td class="table-text"> 21 <div>{{ $task->name }}</div> 22 </td> 23 <!-- Delete Button --> 24 <td> 25 26 </td> 27 </tr> 28 @endforeach 29 </tbody> 30 </table> 31 </div> 32 </div> 33 @endif 34 </div> 35</div> 36@endsection
routes/web.php
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ use App\Task; /* 全タスクをリスト表示するルート(GETリクエスト) */ Route::get('/', function () { $tasks = Task::orderBy('created_at', 'asc')->get(); return view('tasks', [ 'tasks' => $tasks ]); });
試したこと
http://iekasegu.work/column.php?no=27
こちらのサイトを参考に、@yield('content')と@section('content')の「content」をダブルクォーテーションで囲んで見ましたが。同じエラーでした。
残る可能性として、'content'の定数定義をしっかりしなければならないと思うのですが、
そもそも'content'が何故定数として認識されているのかわかりません。
また、どのように定数定義するのか(configフォルダ内の定数定義ファイルに定義するのか、@Yieldの前なのか、@sectionの前なのか、ルーティングのメソッド内なのか、)わかりません。
https://readouble.com/laravel/5.6/ja/blade.html
Laravelの公式ドキュメントを参考にしてみましたが、現在学習中のhttps://beiznotes.org/making-task-list-with-laravel55-2/と同じような処理・説明が書いてあります。
ご解答お待ちしております。
回答1件
あなたの回答
tips
プレビュー