Skip to content

Commit

Permalink
blog route updated
Browse files Browse the repository at this point in the history
  • Loading branch information
codephics committed Aug 17, 2024
1 parent 4a3a17a commit 949dac5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
47 changes: 24 additions & 23 deletions app/Http/Controllers/Global/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,33 @@ public function shop()
]);
}

public function blog()
public function blog($slug = null)
{
$page = Page::where('slug', 'blog')->firstOrFail();
$setting = Setting::first();
$blogs = Blog::all();

return view('frontend.blog.more', [
'page' => $page,
'setting' => $setting,
'blogs' => $blogs
]);
}

public function detail($slug)
{
$page = Blog::where('slug', $slug)->firstOrFail();
$blog = Blog::where('slug', $slug)->firstOrFail();
$setting = Setting::first();
$relatedBlog = Blog::take(4)->get();

return view('frontend.blog.detail', [
'page' => $page,
'blog' => $blog,
'setting' => $setting,
'relatedBlog' => $relatedBlog
]);
if ($slug) {
// Handle the detail view
$page = Blog::where('slug', $slug)->firstOrFail();
$blog = Blog::where('slug', $slug)->firstOrFail();
$relatedBlog = Blog::take(4)->get();

return view('frontend.blog.detail', [
'page' => $page,
'blog' => $blog,
'setting' => $setting,
'relatedBlog' => $relatedBlog
]);
} else {
// Handle the blog listing view
$page = Page::where('slug', 'blog')->firstOrFail();
$blogs = Blog::all();

return view('frontend.blog.more', [
'page' => $page,
'setting' => $setting,
'blogs' => $blogs
]);
}
}

public function overview()
Expand Down
4 changes: 2 additions & 2 deletions resources/views/frontend/blog/detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@
<article>
<figure>
<div class="card shadow mb-5 rounded-3 no-border-card">
<a href="{{ route('blog.detail',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
<a href="{{ route('blog',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
<img src="{{ asset('blog/image/featured/' . $blog->featured_image) }}" class="card-img-top" alt="...">
</a>
<figcaption>
<div class="card-body">
<ul class="d-flex list-unstyled mt-auto">
<li class="me-auto">
<a href="{{ route('blog.detail',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">{{ \Illuminate\Support\Str::limit($blog->title, 60, '...') }}</a>
<a href="{{ route('blog',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">{{ \Illuminate\Support\Str::limit($blog->title, 60, '...') }}</a>
<small>{{ $blog->created_at->format('M d, Y') }}</small>
</li>
<li class="d-flex align-items-center">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/frontend/blog/more.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
<article>
<figure>
<div class="card shadow mb-5 rounded-3 no-border-card">
<a href="{{ route('blog.detail',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
<a href="{{ route('blog',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
<img src="{{ asset('blog/image/featured/' . $blog->featured_image) }}" class="card-img-top" alt="...">
</a>
<figcaption>
<div class="card-body">
<ul class="d-flex list-unstyled mt-auto">
<li class="me-auto">
<a href="{{ route('blog.detail',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">{{ \Illuminate\Support\Str::limit($blog->title, 60, '...') }}</a>
<a href="{{ route('blog',$blog->slug) }}" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">{{ \Illuminate\Support\Str::limit($blog->title, 60, '...') }}</a>
<small>{{ $blog->created_at->format('M d, Y') }}</small>
</li>
<li class="d-flex align-items-center">
Expand Down
3 changes: 1 addition & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
|--------------------------------------------------------------------------
*/

Route::get('blog', [PageController::class, 'blog'])->name('blog');
Route::get('blog/{slug}', [PageController::class, 'detail'])->name('blog.detail');
Route::get('blog/{slug?}', [PageController::class, 'blog'])->name('blog');

/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 949dac5

Please sign in to comment.