【问题标题】:laravel $title is undefined Make the variable optional in the blade template. Replace {{ $title }} with {{ $title ?? '' }}laravel $title is undefined 使变量在刀片模板中成为可选。将 {{ $title }} 替换为 {{ $title ?? '' }}
【发布时间】:2020-10-18 03:12:13
【问题描述】:

$title is undefined Make the variable optional in the blade template. Replace {{ $title }} with {{ $title ?? '' }}

index.blade.php 正在工作

@extends('layouts.app')

@section('content')

  {{ $title }}
  
@endsection

但是 about 和 service 不能使用相同的代码。 在我的 PageController.php 中

    public function index(){
        $title = 'welcome hiii';
        return view('pages.index')->with('title', $title);
    }

    public function about(){
        $title = 'welcome hiiissssssss';
        return view('pages.about')->with('title', $title);
    }

    public function services(){
        $data = array(
            'title' => 'services'
        );
        return view('pages.services')->with($data);
    }

【问题讨论】:

  • Welcome to SO ...错误告诉您如何避免错误...您是否完成了他们的建议?
  • 你是如何定义路由的。我们可以看看你的路线代码吗?
  • 它在哪个页面上为您提供$title 错误?
  • 尽量在您的问题中明确并提供完整的相关数据以及错误详细信息在哪里?您的路线详情在哪里?

标签: php laravel


【解决方案1】:

只有当您flash the data to the session 喜欢进行重定向时,标题才会是一个变量。

你可以使用

return view('pages.services', compact('title'));

或者

return view('pages.services', ['title' => '...']);

【讨论】:

  • 问题不在控制器上。
  • @STA 它在哪里?
猜你喜欢
  • 1970-01-01
  • 2014-07-07
  • 2017-08-08
  • 2014-03-12
  • 1970-01-01
  • 2018-12-24
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
相关资源
最近更新 更多