Support the ongoing development of Laravel.io →
posted 10 years ago
Views
Last updated 1 year ago.
0

Make sure:

 protected $layout='master';

is set in your BaseController, provided that your master layout is named as master.blade.php. This will solve your problem!

Last updated 1 year ago.
0

Thank you very much Usman! It worked as you described, and solved the problem, only to reveal a new one.

In my view, I get the following error when I try to save a post to the database:

ErrorException
Undefined variable: content (View: /var/www/app/views/dash.blade.php)

I cannot seem to find the $content variable anywhere?

Last updated 1 year ago.
0

I get the undefined variable $content error, however it still saves to my database?

Last updated 1 year ago.
0

can you share your savePost controller action? And $content variable is used inside dash.blade.php see for the line:

    <div class="content">
        @if(Session::has('success'))
        <div data-alert class="alert-box round">
            {{Session::get('success')}}
            <a href="#" class="close">&times;</a>
        </div>
        @endif
        {{$content}}
    </div>
Last updated 1 year ago.
0

Hey usm4n! Sorry for getting back to you this late, I didnt see that you had replied to me.

This is part of the controller:

public function showPost(Post $post) { $comments = $post->comments()->where('approved', '=', 1)->get(); $this->layout->title = $post->title; $this->layout->main = View::make('home')->nest('content', 'post.single', compact('post', 'comments')); }

public function newPost()
{
    $this->layout->title = 'New Post';
    $this->layout->main = View::make('dash')->nest('content', 'post.new');
}

public function editPost(Post $post)
{
    $this->layout->title = 'Edit Post';
    $this->layout->main = View::make('dash')->nest('content', 'post.edit', compact('post'));
}

public function deletePost(Post $post)
{
    $post->delete();
    return Redirect::route('post.list')->with('success', 'Post is deleted!');
}

/* post functions */
public function savePost()
{
    $post = [
        'title' => Input::get('title'),
        'content' => Input::get('content'),
    ];
    $rules = [
        'title' => 'required',
        'content' => 'required',
    ];
    $valid = Validator::make($post, $rules);
    if ($valid->passes()) {
        $post = new Post($post);
        $post->comment_count = 0;
        $post->read_more = (strlen($post->content) > 120) ? substr($post->content, 0, 120) : $post->content;
        $post->save();
        return Redirect::to('dash')->with('success', 'Post is saved!');
    } else
        return Redirect::back()->withErrors($valid)->withInput();
}
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Reached reached Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.