Я играю с Laravel, но у меня проблема с контроллером, возвращающим представления. $aboutUs
работает но для $footerText
Я получаю сообщение об ошибке:
Undefined variable: footerText (View:
/Users/user/sublime/blog/resources/views/about-
us.blade.php)
Что я делаю не так и как я могу это исправить?
Вот AboutUsController.php
:
<?php
namespace App\Http\Controllers;
class AboutUsController extends Controller
{
public function index()
{
$aboutUs = "About Us";
return view('about-us', compact("aboutUs"));
}
public function indexTwo()
{
$footerText = "Some more text here";
return view('footer-content', compact("footerText"));
}
}
Вот views/about-us.bladephp
:
@extends('layouts.about-us')
@section('title', $aboutUs)
@section('about-content')
<div class="container">
<h1>{{ $aboutUs }}</h1> {{-- This works --}}
<h1>{{ $footerText }}</h1> {{-- This doesn't work --}}
</div>
@endsection
Возвращая 2 вещи в одной функции, попробуйте это с помощью with
,
public function index()
{
$aboutUs = "About Us";
$footerText = "Some more text here";
return view('about-us', compact("aboutUs"))
->with('footer-content', compact("footerText"));
}
Других решений пока нет …