Skip to content

Commit ae1362c

Browse files
committed
change templates
1 parent 0f154eb commit ae1362c

File tree

11 files changed

+185
-206
lines changed

11 files changed

+185
-206
lines changed

app/Http/Controllers/TagsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TagsController extends Controller
1010
public function index(Tag $tag)
1111
{
1212
$posts = $tag->posts()->with('tags')->get();
13-
return view('index', compact('posts'));
13+
$news = $tag->news()->with('tags')->get();
14+
return view('index', compact('posts', 'news'));
1415
}
1516
}

app/Providers/AppServiceProvider.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Providers;
44

5+
use App\NewTag;
6+
use App\PostTag;
57
use App\Tag;
68
use Illuminate\Support\ServiceProvider;
79

@@ -15,7 +17,13 @@ class AppServiceProvider extends ServiceProvider
1517
public function register()
1618
{
1719
view()->composer('layouts.aside-tags', function ($view) {
18-
$view->with('tagsCloud', Tag::all());
20+
$postsTags = PostTag::all()->unique('tag_id')->keyBy('tag_id');
21+
$newsTags = NewTag::all()->unique('tag_id')->keyBy('tag_id');
22+
$keys = $postsTags->mergeRecursive($newsTags)->keyBy('tag_id')->keys()->sort();
23+
24+
$postsAndNewsTags = Tag::all()->whereIn('id', $keys);
25+
26+
$view->with('tagsCloud', $postsAndNewsTags);
1927
});
2028
}
2129

@@ -26,6 +34,6 @@ public function register()
2634
*/
2735
public function boot()
2836
{
29-
//
37+
3038
}
3139
}

resources/views/admin/news.blade.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,7 @@
55
@endsection
66

77
@section('content')
8-
<main class="py-4" style="min-height: 88vh">
9-
<div class="container">
10-
<section class="news-section news mb-2 row">
11-
<h2 class="news__header col-12 order-2 order-sm-0">News</h2>
12-
13-
<div class="news-section__news new col-sm-8 col-lg-10 order-2 order-sm-0">
14-
@forelse($news as $new)
15-
<div class="new__item d-flex col-md-6 ">
16-
<div class="new__heading d-flex flex-column p-3 w-100 border rounded mb-4 shadow-sm">
17-
<strong class="mb-2 text-primary">new #{{ $new->id }}</strong>
18-
19-
<h3 class="new__name mb-0">{{ $new->name }}</h3>
20-
21-
<div class="new__created-at mb-1 text-muted">{{ $new->created_at->toFormattedDateString() }}</div>
22-
23-
<p class="new__preview card-text flex-grow-1 text-justify"> {{ str_limit($new->text, $limit = 200, $end = '...') }} </p>
24-
25-
@if($new->tags->isNotEmpty())
26-
<div class="post__tags mb-2">
27-
@foreach($new->tags as $tag)
28-
<span class="badge badge-info text-white">{{ $tag->name }}</span>
29-
@endforeach
30-
</div>
31-
@endif
32-
33-
<div class="new__actions d-flex justify-content-end">
34-
<a href="{{ route('news.show', $new) }}" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Read</a>
35-
36-
<a href="{{ route('news.edit', $new) }}" class="btn btn-outline-secondary mx-1" style="width: 80px; font-size: 0.7rem">Edit</a>
37-
38-
<form method="post" action="{{ route('news.destroy', $new) }}">
39-
@csrf
40-
@method('DELETE')
41-
42-
<button type="submit" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Delete</button>
43-
</form>
44-
</div>
45-
</div>
46-
</div>
47-
@empty
48-
<p class="no-news">No available news yet</p>
49-
@endforelse
50-
</div>
51-
</section>
52-
</div>
53-
</main>
8+
@include('layouts.news.news-section')
549
@endsection
5510

5611
@section('footer')

resources/views/admin/posts.blade.php

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,7 @@
55
@endsection
66

77
@section('content')
8-
<main class="py-4" style="min-height: 88vh">
9-
<div class="container">
10-
<section class="posts-section mb-2">
11-
<h2 class="posts-section__header">Posts</h2>
12-
13-
@if ($posts->count())
14-
<div class="posts-section__posts row post">
15-
@foreach($posts as $post)
16-
<div class="post__item col-md-6 ">
17-
<div class="post__intro text-break row py-2 no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
18-
<div class="post__heading col-6 p-4 d-flex flex-column position-static" style="height: 280px;">
19-
<strong class="d-inline-block mb-2 text-primary">Post #{{ $post->id }}</strong>
20-
21-
<h3 class="post__name mb-0">{{ $post->name }}</h3>
22-
23-
<div class="post__created-at mb-1 text-muted">{{ $post->created_at->toFormattedDateString() }}</div>
24-
25-
<p class="post__preview card-text mb-auto text-justify"> {{ str_limit($post->text, $limit = 100, $end = '...') }} </p>
26-
27-
<a href="{{ route('posts.show', $post->id) }}" class="post__view">Continue reading</a>
28-
</div>
29-
30-
<div class="post__photo col-6 d-none d-lg-flex align-items-center p-2">
31-
<svg class="bd-placeholder-img" width="auto" height="250" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Thumbnail">
32-
<title>Placeholder</title>
33-
<rect width="100%" height="100%" fill="#55595c"></rect>
34-
<text x="35%" y="50%" fill="#eceeef" dy=".3em">Thumbnail</text>
35-
</svg>
36-
</div>
37-
38-
<div class="d-flex col-12 justify-content-end pr-2">
39-
<a href="/posts/{{ $post->id }}/edit" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Edit</a>
40-
41-
<form method="post" action="{{ route('posts.destroy', $post) }}">
42-
@csrf
43-
@method('DELETE')
44-
<button type="submit" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Delete</button>
45-
</form>
46-
</div>
47-
</div>
48-
</div>
49-
@endforeach
50-
</div>
51-
@else
52-
<p class="no-posts">No available posts yet</p>
53-
@endif
54-
</section>
55-
</div>
56-
</main>
8+
@include('layouts.posts.posts-section')
579
@endsection
5810

5911
@section('footer')

resources/views/layouts/aside-tags.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@if($tagsCloud->isNotEmpty())
33
<h3 class="tags-cloud__header text-center">Available Tags</h3>
44

5-
@include('layouts.posts.tags', ['tags' => $tagsCloud])
5+
@include('layouts.tags.tags', ['tags' => $tagsCloud])
66
@else
77
<h3 class="tags-cloud__header text-center">No available tags</h3>
88
@endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<main class="py-4" style="min-height: 88vh">
2+
<div class="container">
3+
<section class="news-section news mb-2 row">
4+
<h2 class="news__header order-2 order-sm-0 col-12">News</h2>
5+
6+
<div class="news-section__news new col-sm-8 col-lg-10 order-2 order-sm-0">
7+
@forelse($news as $new)
8+
<div class="new__item d-flex">
9+
<div class="new__heading d-flex flex-column p-3 w-100 border rounded mb-4 shadow-sm">
10+
<strong class="mb-2 text-primary">new #{{ $new->id }}</strong>
11+
12+
<h3 class="new__name mb-0">{{ $new->name }}</h3>
13+
14+
<div class="new__created-at mb-1 text-muted">{{ $new->created_at->toFormattedDateString() }}</div>
15+
16+
<p class="new__preview card-text flex-grow-1 text-justify"> {{ str_limit($new->text, $limit = 200, $end = '...') }} </p>
17+
18+
@if($new->tags->isNotEmpty())
19+
<div class="post__tags mb-2">
20+
@foreach($new->tags as $tag)
21+
<span class="badge badge-info text-white">{{ $tag->name }}</span>
22+
@endforeach
23+
</div>
24+
@endif
25+
26+
<div class="d-flex justify-content-end">
27+
<a href="{{ route('news.show', $new) }}" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Read</a>
28+
29+
@if(auth()->user()->hasRole('admin'))
30+
<a href="{{ route('news.edit', $new) }}" class="btn btn-outline-secondary mx-1" style="width: 80px; font-size: 0.7rem">Edit</a>
31+
32+
<form method="post" action="{{ route('news.destroy', $new) }}">
33+
@csrf
34+
@method('DELETE')
35+
36+
<button type="submit" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Delete</button>
37+
</form>
38+
@endif
39+
</div>
40+
</div>
41+
</div>
42+
@empty
43+
<p class="no-news">No available news yet</p>
44+
@endforelse
45+
</div>
46+
47+
@include('layouts.aside-tags')
48+
</section>
49+
</div>
50+
</main>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<main class="py-4" style="min-height: 88vh">
2+
<div class="container">
3+
<section class="posts-section mb-2">
4+
<h2 class="posts-section__header">Posts</h2>
5+
6+
@if ($posts->count())
7+
<div class="posts-section__posts row post">
8+
@foreach($posts as $post)
9+
<div class="post__item col-md-6 ">
10+
<div class="post__intro text-break row py-2 no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
11+
<div class="post__heading col-6 p-4 d-flex flex-column position-static" style="height: 280px;">
12+
<strong class="d-inline-block mb-2 text-primary">Post #{{ $post->id }}</strong>
13+
14+
<h3 class="post__name mb-0">{{ $post->name }}</h3>
15+
16+
<div class="post__created-at mb-1 text-muted">{{ $post->created_at->toFormattedDateString() }}</div>
17+
18+
<p class="post__preview card-text mb-auto text-justify"> {{ str_limit($post->text, $limit = 100, $end = '...') }} </p>
19+
20+
@if($post->tags->isNotEmpty())
21+
<div class="post__tags mb-2">
22+
@foreach($post->tags as $tag)
23+
<span class="badge badge-info text-white">{{ $tag->name }}</span>
24+
@endforeach
25+
</div>
26+
@endif
27+
28+
<a href="{{ route('posts.show', $post->id) }}" class="post__view">Continue reading</a>
29+
</div>
30+
31+
<div class="post__photo col-6 d-none d-lg-flex align-items-center p-2">
32+
<svg class="bd-placeholder-img" width="auto" height="250" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Thumbnail">
33+
<title>Placeholder</title>
34+
<rect width="100%" height="100%" fill="#55595c"></rect>
35+
<text x="35%" y="50%" fill="#eceeef" dy=".3em">Thumbnail</text>
36+
</svg>
37+
</div>
38+
39+
<div class="d-flex col-12 justify-content-end pr-2">
40+
<a href="{{ route('posts.edit', $post) }}" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Edit</a>
41+
42+
<form method="post" action="{{ route('posts.destroy', $post) }}">
43+
@csrf
44+
@method('DELETE')
45+
<button type="submit" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Delete</button>
46+
</form>
47+
</div>
48+
</div>
49+
</div>
50+
@endforeach
51+
</div>
52+
@else
53+
<p class="no-posts">No available posts yet</p>
54+
@endif
55+
</section>
56+
</div>
57+
</main>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@extends('layouts.app')
2+
3+
@section('header')
4+
@include('layouts.base.header')
5+
@endsection
6+
7+
@section('content')
8+
<main class="py-4" style="min-height: 88vh">
9+
<div class="container">
10+
<div class="view-block">
11+
<section class="posts-section mb-2 row flex-column flex-sm-row">
12+
<h3 class="posts-section__header col-12 order-2 order-sm-0 text-center">Latest posts</h3>
13+
14+
@if ($posts->count())
15+
<div class="posts-section__posts order-2 order-sm-0 col-12 col-sm-8 col-lg-10 post">
16+
@foreach($posts as $post)
17+
<div class="post__item">
18+
<div class="post__intro text-break row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
19+
<div class="post__heading col-12 col-lg-6 p-4 d-flex flex-column" style="height: 280px;">
20+
<strong class="d-inline-block mb-2 text-primary">Post #{{ $post->id }}</strong>
21+
22+
<h3 class="post__name mb-0">{{ $post->name }}</h3>
23+
24+
<div class="post__created-at mb-1 text-muted">{{ $post->created_at->toFormattedDateString() }}</div>
25+
26+
<p class="post__preview card-text mb-auto text-justify"> {{ str_limit($post->text, $limit = 100, $end = '...') }} </p>
27+
28+
@if($post->tags->isNotEmpty())
29+
<div class="post__tags mb-2">
30+
@foreach($post->tags as $tag)
31+
<a href="{{ route('tags.show', $tag) }}" class="badge badge-info text-white">{{ $tag->name }}</a>
32+
@endforeach
33+
</div>
34+
@endif
35+
36+
<a href="{{ route('posts.show', $post->id) }}" class="post__view">Continue reading</a>
37+
</div>
38+
39+
<div class="post__photo col-6 d-none d-lg-flex align-items-center p-2">
40+
<svg class="bd-placeholder-img" width="auto" height="250" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: Thumbnail">
41+
<title>Placeholder</title>
42+
<rect width="100%" height="100%" fill="#55595c"></rect>
43+
<text x="35%" y="50%" fill="#eceeef" dy=".3em">Thumbnail</text>
44+
</svg>
45+
</div>
46+
</div>
47+
</div>
48+
@endforeach
49+
</div>
50+
@else
51+
<p class="no-posts">No available posts yet</p>
52+
@endif
53+
</section>
54+
</div>
55+
</div>
56+
</main>
57+
@endsection
58+
59+
@section('footer')
60+
@include('layouts.base.footer')
61+
@endsection

resources/views/news/index.blade.php

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,7 @@
55
@endsection
66

77
@section('content')
8-
<main class="py-4" style="min-height: 88vh">
9-
<div class="container">
10-
<section class="news-section news mb-2 row">
11-
<h2 class="news__header col-12 order-2 order-sm-0">News</h2>
12-
13-
<div class="news-section__news new col-sm-8 col-lg-10 order-2 order-sm-0">
14-
@forelse($news as $new)
15-
<div class="new__item d-flex col-md-6">
16-
<div class="new__heading d-flex flex-column p-3 w-100 border rounded mb-4 shadow-sm">
17-
<strong class="mb-2 text-primary">new #{{ $new->id }}</strong>
18-
19-
<h3 class="new__name mb-0">{{ $new->name }}</h3>
20-
21-
<div class="new__created-at mb-1 text-muted">{{ $new->created_at->toFormattedDateString() }}</div>
22-
23-
<p class="new__preview card-text flex-grow-1 text-justify"> {{ str_limit($new->text, $limit = 200, $end = '...') }} </p>
24-
25-
@if($new->tags->isNotEmpty())
26-
<div class="post__tags mb-2">
27-
@foreach($new->tags as $tag)
28-
<span class="badge badge-info text-white">{{ $tag->name }}</span>
29-
@endforeach
30-
</div>
31-
@endif
32-
33-
<div class="d-flex justify-content-end">
34-
<a href="{{ route('news.show', $new) }}" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Read</a>
35-
36-
@if(auth()->user()->hasRole('admin'))
37-
<a href="{{ route('news.edit', $new) }}" class="btn btn-outline-secondary mx-1" style="width: 80px; font-size: 0.7rem">Edit</a>
38-
39-
<form method="post" action="{{ route('news.destroy', $new) }}">
40-
@csrf
41-
@method('DELETE')
42-
43-
<button type="submit" class="btn btn-outline-secondary" style="width: 80px; font-size: 0.7rem">Delete</button>
44-
</form>
45-
@endif
46-
</div>
47-
</div>
48-
</div>
49-
@empty
50-
<p class="no-news">No available news yet</p>
51-
@endforelse
52-
</div>
53-
54-
@include('layouts.aside-tags')
55-
</section>
56-
</div>
57-
</main>
8+
@include('layouts.news.news-section')
589
@endsection
5910

6011
@section('footer')

0 commit comments

Comments
 (0)