Malchesador
Malchesador

Reputation: 795

Method Illuminate\View\View::__toString() must not throw an exception when loading views inside view in Laravel

I am loading a header and footer in each page without using blade and just using echo View:make('templates/header'); and at the end of the page likewise with the footer.

I am loading these same header and footer views in exactly the same manner in other views without problems, but when I call this particular view from my controller, I get this very non-informational Laravel error message. It's very basic HTML right now as I'm still in the building/testing phase. I don't know why loading the header and footer views in other views I'm using works, but here they're crashing.

Here's the code:

<?php 
echo View::make('templates/header');
?>
<div class="row">
    <div class="col-md-5 col-md-offset-3">
    <h1>Record Saved!</h1>
    </div>
</div>
<?
echo View::make('templates/footer');

Is there any way to get more information out of Laravel to find out what it's not liking?

Upvotes: 0

Views: 3538

Answers (2)

Ravi Hirani
Ravi Hirani

Reputation: 6539

In blade template file, You do not need to write <?php ?> Tag.

also use include instead of View::make in blade file.

@include('templates.header');
<div class="row">
    <div class="col-md-5 col-md-offset-3">
    <h1>Record Saved!</h1>
    </div>
</div>
@include('templates.footer');

Note: Blade file must has extension .blade.php

Hope it will help you :-)

Upvotes: 0

Simon Wicki
Simon Wicki

Reputation: 4059

__toString() calls the render() method on View (source). the exception is therefore thrown within templates.footer or templates.header.

Upvotes: 1

Related Questions