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!
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?
I get the undefined variable $content error, however it still saves to my database?
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">×</a>
</div>
@endif
{{$content}}
</div>
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();
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community