Skip to content

Commit

Permalink
Fix pass in blog slug
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed Aug 9, 2024
1 parent 4d31723 commit da88fba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions app/Livewire/BlogView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

namespace App\Livewire;

use App\Models\Blog;
use Illuminate\View\View;
use Livewire\Component;

class BlogView extends Component
{
public $blog;

public function mount($blog): void
public function mount($slug): void
{
$this->blog = $blog;
$this->blog = Blog::with(['user', 'images'])->where('slug', $slug)->first();
}

public function render(): View
{
return view('blogs.show')->layout('blogs.layout');
return view('blogs.show')->layout('layouts.guest');
}
}
2 changes: 1 addition & 1 deletion resources/views/livewire/blog-renderer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="mt-4 text-gray-700 leading-relaxed">
{!! Str::limit($blog->content, 300) !!}
</div>
<a href="{{ route('blog.show', $blog->slug) }}" class="text-blue-500 mt-4 inline-block">Read More</a>
<a href="{{ route('blog.show', $blog) }}" class="text-blue-500 mt-4 inline-block">Read More</a>
</div>
</div>
@empty
Expand Down
5 changes: 2 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use App\Livewire\BlogMaker;
use App\Livewire\AutoOrderCreate;
use App\Livewire\BlogRenderer;
use App\Livewire\BlogView;
use App\Livewire\EditProfile;
use App\Livewire\ManageUsers;
use App\Livewire\OrderCreate;
Expand Down Expand Up @@ -73,9 +74,7 @@
Route::post('/newsletter/subscribe', [PagesController::class, 'subscribe'])->name('newsletter.subscribe');

Route::get('/blog', BlogRenderer::class)->name('blog');
Route::get('/blogs/{blog:slug}', function (Blog $blog) {
return view('blogs.show', compact('blog'));
})->name('blog.show');
Route::get('/blogs/{slug}', BlogView::class)->name('blog.show');


require __DIR__.'/auth.php';

0 comments on commit da88fba

Please sign in to comment.