繁体   English   中英

laravel $title 未定义 使变量在刀片模板中可选。 将 {{ $title }} 替换为 {{ $title?? '' }}

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

$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);
    }

如果您将 flash 数据发送到 session就像进行重定向一样,标题只会是一个变量。

相反,您可以使用

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

或者

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM