R
R
Ruslan Gillyazanov2018-10-14 18:05:54
Laravel
Ruslan Gillyazanov, 2018-10-14 18:05:54

Blade template engine variable inheritance in Laravel child templates?

There is an IndexController controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class IndexController extends Controller
{
    public function getIndex()
    {
        $year = '2018';
        return view('index', ['year' => $year]);
    }
}

route
Route::get('/', '[email protected]')->name("home");

and template welcome.blade.php
@section('hello')
<h1>Hello, world! {{ $year }}</h1>
@show

Why does the Undefined variable: year error appear if I inherit from the template welcome.blade.php ?
@extentds('welcome')

@section('hello')
    @parent
    <h2>Hello, {{ $year }}</h2>
@endsection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Gillyazanov, 2018-10-17
@trycode

Found a solution .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question