Laravel 4 patterns causing FatalErrorException?

I get an inexplicable FatalErrorException when trying to implement a simple page layout using blade templates. I'm not sure if this is what I am doing wrong, or Laravel. I follow the L4 documentation guide on Templating, and my code seems to follow it. Here is my code.

Application / routes.php:

<?php Route::get('/', ' HomeController@showWelcome '); 

app / views / home / welcome.blade.php:

 @extends('layouts.default') @section('content') <h1>Hello World!</h1> @stop 

app / views / layouts / default.blade.php:

 <!doctype html> <html> <head> <title>The Big Bad Barn (2013)</title> </head> <body> <div> @yield('content') </div> </body> </html> 

application / controllers / HomeController.php:

 <?php class HomeController extends BaseController { protected $layout = 'layouts.default'; public function showWelcome() { $this->layout->content = View::make('home.welcome'); } } 

Laravel just throws a FatalErrorException. Is the "Syntax error unexpected" displayed on the output error page? ". The file locator generates inside the PHP storage / views directory, where

 <?php echo $__env->make('layouts.default') <?php $__env->startSection('content', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>; ?> <h1>Hello World!</h1> <?php $__env->stopSection(); ?> 
+4
source share
3 answers

Yesterday I ran into the same problem as you, however the other answers did not help solve my problem. You probably already understood this, but perhaps this message doesnโ€™t allow others to spend as much time as I found out whatโ€™s wrong when itโ€™s such a small (but frustrating!) Thing.

I use Notepad ++ as a text editor, and for some strange reason, he decided to use the "MAC" format as the End-Of-Line (EOL) format. Blade seems to be unable to handle this. Use the conversion function (in Notepad ++: Edit -> EOL Conversion) to convert to Windows format and it will work fine ...

+8
source

Your controller should simply return View :: make ("home.welcome") instead of binding to the layout.

In the welcome view, the layout is then called, so in this case the controller only touches the body template.

Edit to show an example controller:

 class HomeController extends BaseController { public function showWelcome() { return View::make('home.welcome'); } } 
0
source

Eric already gave the correct answer, I just wanted to add that if you want to use

 protected $layout = 'layouts.default'; 

in your HomeController, then leave the showWelcome action intact and delete this line

 @extends('layouts.default') 

from welcome.blade.php file. That should work too.

Regards, Vlad

0
source

Source: https://habr.com/ru/post/1480726/


All Articles