@yield does not display content

2

I'm learning Laravel 5.1, I ran into an error using @yield . I can not pass the contents of another file to the file where I want to include it.

Next I have the content I want to insert into the default-home.blade.php file inside the layouts folder:

@extends('layouts.default-home')
@section('content')      

<section id="feature_two">
<div class="container">
    <div class="row">

        <!-- Feature Two Description -->
        <div id="feature_2_description" class="col-md-5 feature_description triggerAnimation animated" data-animate="fadeInLeft">

            <h2>Super easy to customize and well detailed for beginners</h2>

            <p>Vestibulum at est vel felis adipiscing tincidunt. Proin quis diam ac lectus pretium mollis interdum sed erat. Phasellus eget
                neque eu ipsum laoreet suscipit tincidunt suscipit purus rutrum 
            </p>

            <p>Etiam euismod, ligula nec volutpat tempor, risus lerisque tincidunt purus libero. Fusce tincidunt ligula, nec sagittis turpis</p>

        </div><!-- End Feature Two Description -->

        <!-- Feature Two Image -->
        <div id="feature_2_image" class="col-md-7 feature_image text-right triggerAnimation animated" data-animate="fadeInRight">
            <img class="img-responsive" src="img/thumbs/feature_two_img.png" alt="feature_two_img">
        </div>

    </div><!-- End row -->  
</div><!-- End container -->
</section>

@stop

This is file with @yield inserted, @includes are working:

<body class="notransition"  ng-app>

    @include('layouts.head-home')
    @yield('content') 
    @include('layouts.footer-home')

    <div id="status"></div>

</body>

In this case, the site I'm developing uses the links in the menu to jump to another part of the site below, in addition to that content does not display the console displays this error every time I scroll the page or click the link for scrolling:

  

Uncaught TypeError: Can not read property 'top' of undefined

File routes.php:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/


Route::get('','Site\HomeController@home');
Route::get('/','Site\HomeController@home');


?>

Controller:

<?php

namespace App\Http\Controllers\Site;


use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class HomeController extends Controller {

    public function home(){
        return view('site/home'); //chamando a view home.blade.php
    }
}
    
asked by anonymous 24.07.2015 / 02:16

1 answer

1

From the comments I noticed some issues that need to be fixed.

In the route file, you set a route to Site\HomeController@home twice. The path '' ends up being unnecessary, so you can delete it:

<?php

Route::get('/','Site\HomeController@home');

Another point is that your route is pointing to the HomeController class within the app/Http/Controllers/Site directory. Since the Laravel application follows the PSR-4 , the namespace of this controller must contain the final Site :

<?php

namespace App\Http\Controllers\Site;

If you do not have a good reason to move the controller to a sub-folder, keep it in the app/Http/Controllers folder.

Fixed these issues, let's view the view.

To return the view with the content on your home page, simply return the view path this way in the home method of HomeController :

public function home(){
    return view('main');  
    // caso a view esteja em alguma pasta, utilize o . como separador
    // como você fez com o layouts.default-home
    // return view('pasta.main');  
}

Finally, you can return the page directly from the route files by an anonymous function, thus eliminating the need for the controller on simple pages:

Route::get('/', function () {
    return view('pasta.main');
});
    
24.07.2015 / 03:14