I would like to be able to display different content depending on which variable is called in the url.Ignoring the fact $slug is slug, let's say it's a post id instead so if $id is active then show just the post else if $month is active show all posts from that month elseif $month and $id = null show all. That's what I'm trying to achive
Routes.php
Route::get('blog/{slug}', ['as' => 'blog.slug', 'uses' => 'BlogController@getSlug']);
Route::get('blog/{month}', ['as' => 'blog.slug', 'uses' => 'BlogController@getSlug']);
BlogController.php
<?php
class BlogController extends BaseController {
public function BlogIndex()
{
//get the posts from the database by asking the Active Record for "all"
$blogs = Blog::all();
$blogs = DB::table('blogs')->paginate(3);
// and create a view which we return - note dot syntax to go into folder
return View::make('pages.blog', array('blogs' => $blogs));
}
public function ShowbySlug($slug)
{
$blogs = Blog::where('slug', '=', $slug)->get();
// show the view with blog posts (app/views/pages/blog.blade.php)
return View::make('pages.blog')
->with('slug', $slug)
->with('blogs', $blogs);
}
public function ShowbyMonth($month)
{
$blogs = Blog::where('month', '=', $month)->get();
// show the view with blog posts (app/views/pages/blog.blade.php)
return View::make('pages.blog')
->with('month', $month)
->with('blogs', $blogs);
}
}
blog.blade.php
@foreach ($blogs as $blog)
@if(isset($blogs))
<div class="blog-outer-wrap">
<img src="images/blog/{{ $blog->img}}">
<div class="blog-header">{{ $blog->header }}</div>
<div class="blog-text">{{ $blog->content }}</div>
<a href="{{ URL::route('blog.slug', [$blog->slug]) }}">
</div>
@elseif(isset($slug))
<div class="blog-outer-wrap">
<img src="images/blog/{{ $blog->img}}">
<div class="blog-header">{{ $blog->header }}</div>
<div class="blog-text">{{ $blog->content }}</div>
</div>
@endif
@endforeach