2
votes

While creating a basic item detail page for a basic blog I've run into a problem with Laravel's @extends not working when pulling in a master layout template. The content from the detail page loads just fine but the master page HTML is not there at all and I'm not getting any errors.

In my routes:

Route::get('blog', 'BlogController@public_index');
Route::get('blog/{id}', 'BlogController@public_single');

In my BlogController:

public function public_single($id) {
    $blog = Blog::find($id);
    return View::make('public.blog_single') -> with('blog', $blog);
}

At the very top of the blog_single template:

@extends('layouts.public')

All other templates that use this master layout work as expected.

My views directory structure:

views
  |
  |layouts
  |    |
  |    | admin.blade.php
  |    | public.blade.php
  |
  |public
      |
      |blog.blade.php
      |blog_single.blade.php

One thing I'm wondering is if the fact that this page looks like it's rendering from a subdirectory is an issue. Here is an example:

This works:

www.mydomain.com/blog

This doesn't:

www.mydomain.com/blog/1

I've looked through the Laravel docs and don't see an answer there. Any ideas? Thanks.

2
what is your file and directory structure in /app/views/ ? please update your question.Gadoma
Do you have a route Route::get('blog', 'aControler'); ?Fractaliste
@Gadoma, I've included it above.Rich Coy
@Fractaliste, Yes I have that, I added it above to the question. I did not add it the first time since it works and I did not want to confuse the subject more than it already was.Rich Coy
You said All other templates that use this master layout work as expected, so what is the difference between this (blog_single) and other views ?The Alpha

2 Answers

2
votes

Have you tried to add an absolute path to the master style references?

For example:

<link rel="stylesheet" href="css/bootstrap.min.css">

Has to be:

<link rel="stylesheet" href="/css/bootstrap.min.css">

In all the url's we use. This worked for me :)

1
votes

Okay, not sure how this fixed it, hopefully someone can give me a little detail.

I found this line of code at the bottom of the blog_single.blade.php file:

<div class="text-center">{{ $blogs->links() }}</p>

That is leftover from a copy/paste of the blog.blade.php file and obviously on a detail page I don't need pagination. I removed that one line of code and now the templates work as they should. Wondering why Laravel did not throw some sort of error if it was choking on that line, or why that line would effect the whole master file from getting included in the first place.

Anyway, it's fixed.