Commit c3bd519b authored by Amelia Priti Usparida's avatar Amelia Priti Usparida
Browse files

coba

parent 66527ac4
No related merge requests found
Showing with 59 additions and 7 deletions
+59 -7
......@@ -10,4 +10,9 @@ class Category extends Model
use HasFactory;
protected $guarded = ['id'];
public function post()
{
return $this->hasMany(Post::class);
}
}
@extends('layouts/main')
@section('container')
<h1 class="mb-5">Post Categories : {{ $category}}</h1>
@foreach ($categories as $categories)
,ul>
<li>
<h2><a href="/categories/{{ $category->slug }}">{{ $category->name}}</a></h2>
</li>
</ul>
@endforeach
@endsection
@extends('layouts/main')
@section('container')
<h1 class="mb-5">Post Category : {{ $category}}</h1>
@foreach ($category as $category)
<article>
<h2><a href="/posts/{{ $post->slug }}">{{ $post->title}}</a></h2>
<p>{{ $post->excerpt}}</p>
</article>
@endforeach
@endsection
@extends('layouts.main')
@section('container')
<article>
<h2>{{ $post->title }}</h2>
<h5>{{ $post->author }}</h5>
{!! $post->body !!}
</article>
<h1 class="mb-5"{{ $post->title }}</h1>
<p>By. Amelia Priti Usparida in <a href="/categories/(($post->category->slug}}">{{ $post->category->name}}</a></p>
{!! $post->body !!}
<a href="/posts">Back to Posts</a>
<a href="/blog">Back to Posts</a>
@endsection
\ No newline at end of file
......@@ -3,7 +3,7 @@
use App\Models\Post;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostController;
use App\Models\Category;
/*
|--------------------------------------------------------------------------
......@@ -37,3 +37,17 @@
//halaman single post
Route::get('posts/{post:slug}', [PostController::class,'show']);
Route::get('/categories', function(){
return view('category', [
'title' => 'Post Categories',
'categories' => Category::all()
]);
})
Route::get('/categories/{category:slug}', function(Category $category){
return view('category', [
'title' => $category->name,
'posts' => $category->posts,
'category' => $category->name,
]);
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment