Skip to content

Commit 70be13c

Browse files
committed
feat: Enhance blog shortcodes with new features and improvements
- Updated Blog shortcode to retrieve related blogs and pass them to the view. - Refactored BlogTags shortcode to fetch tags using the blog facade. - Enhanced Blogs shortcode to filter by category and paginate results. - Modified RecentBlogs shortcode to use the blog service for fetching recent blogs. - Updated app-settings.json to correct blog menu links. - Added new blog-categories, blog-meta, related-blogs, and other shortcodes views. - Introduced BlogCategories shortcode to display blog categories with optional counts. - Created BlogDatetime shortcode to format and display blog creation date. - Implemented BlogMeta and BlogReadtime shortcodes for displaying additional blog information. - Developed RelatedBlogs shortcode to show related articles based on the current blog. - Added Blog facade for easier access to blog-related functionalities. - Implemented BlogService to manage blog data retrieval and caching. - Introduced ViewComposerServiceProvider for handling view-related logic.
1 parent f6f1406 commit 70be13c

31 files changed

+1483
-758
lines changed

database/migrations/2023_04_22_110537_create_blogs_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ public function up()
1919
Schema::create('blogs', function (Blueprint $table) {
2020
$table->id();
2121
$table->string('title');
22+
$table->string('category')->nullable()->index();
2223
$table->string('slug')->unique()->index();
2324
$table->longText('description');
25+
$table->{$this->jsonable()}('options')->nullable();
2426
$table->string('meta_title')->nullable();
2527
$table->string('meta_keywords')->nullable();
2628
$table->string('meta_description')->nullable();

database/migrations/2024_04_23_205120_create_pages_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function up(): void
1919
$table->string('title');
2020
$table->string('slug')->unique();
2121
$table->{$this->jsonable()}('data')->nullable();
22+
$table->{$this->jsonable()}('options')->nullable();
2223
$table->string('meta_title')->nullable();
2324
$table->string('meta_keywords')->nullable();
2425
$table->string('meta_description')->nullable();

lib/helpers.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,21 @@ function theme($path, $themeName = null)
574574
return app(Mix::class)(...func_get_args());
575575
}
576576
}
577+
578+
if (!function_exists('blog')) {
579+
/**
580+
* Get the current blog from the request.
581+
*
582+
* @param string|null $key
583+
* @param mixed $default
584+
* @return mixed|\Coderstm\Models\Blog
585+
*/
586+
function blog($key = null, $default = null)
587+
{
588+
if ($key) {
589+
return request()->input('blog') ? optional(request()->input('blog'))->$key ?? $default : $default;
590+
}
591+
592+
return request()->input('blog');
593+
}
594+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@if ($categories->count())
2+
<div class="blog-categories card-body {{ $class ?? '' }}">
3+
<h5 class="card-title">Categories</h5>
4+
@if ($layout === 'list')
5+
<ul class="list-unstyled mb-0">
6+
@foreach ($categories as $item)
7+
<li>
8+
<a class="text-decoration-none d-flex justify-content-between"
9+
href="{{ url('/blog?category=' . urlencode($item['category'])) }}">
10+
<span> {{ $item['category'] }}</span>
11+
@if ($count === 'true')
12+
<span class="badge bg-light text-dark">{{ $item['count'] }}</span>
13+
@endif
14+
</a>
15+
</li>
16+
@endforeach
17+
</ul>
18+
@elseif($layout === 'inline')
19+
@foreach ($categories as $item)
20+
<a href="{{ url('/blog?category=' . urlencode($item['category'])) }}"
21+
class="badge bg-light text-dark m-1">
22+
{{ $item['category'] }}
23+
@if ($count === 'true')
24+
<span class="badge bg-secondary rounded-pill">{{ $item['count'] }}</span>
25+
@endif
26+
</a>
27+
@endforeach
28+
@else
29+
<div class="list-group">
30+
@foreach ($categories as $item)
31+
<a href="{{ url('/blog?category=' . urlencode($item['category'])) }}"
32+
class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
33+
{{ $item['category'] }}
34+
@if ($count === 'true')
35+
<span class="badge bg-primary rounded-pill">{{ $item['count'] }}</span>
36+
@endif
37+
</a>
38+
@endforeach
39+
</div>
40+
@endif
41+
</div>
42+
@endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="article-meta mb-4">
2+
<div class="d-flex flex-wrap align-items-center gap-3 mb-3">
3+
@if ($featured)
4+
<span class="badge bg-primary fs-6">Featured</span>
5+
@endif
6+
<span class="badge bg-success fs-6">{{ $category }}</span>
7+
<span class="text-white-50">
8+
<i class="fas fa-calendar me-1"></i>
9+
{{ $datetime->format('F j, Y') }}
10+
</span>
11+
<span class="text-white-50">
12+
<i class="fas fa-clock me-1"></i>
13+
{{ $readtime }} min read
14+
</span>
15+
</div>
16+
</div>
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
<aside class="widget widget--tagcloud with-title">
2-
<h3 class="widget--title">Tags</h3>
3-
<div class="tagcloud">
4-
@foreach ($tags as $tag)
5-
<a href="javascript:void(0);" class="tag-cloud-link">{{ $tag->label }}</a>
6-
@endforeach
7-
</div>
8-
</aside>
1+
@foreach ($tags as $item)
2+
<span class="badge bg-light text-dark">{{ $item['label'] }}</span>
3+
@endforeach
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div class="card-body">
2+
<h5 class="card-title">{{ $title }}</h5>
3+
<div class="related-posts">
4+
@foreach ($blogs as $blog)
5+
<div class="related-post mb-3">
6+
<div class="d-flex">
7+
@if (isset($blog['thumbnail']['url']))
8+
<img src="{{ $blog['thumbnail']['url'] }}" alt="{{ $blog->title }}" class="me-3 rounded"
9+
width="60" height="60" />
10+
@else
11+
<img src="/statics/img/gym/blog1.jpg" alt="{{ $blog->title }}" class="me-3 rounded"
12+
width="60" height="60" />
13+
@endif
14+
<div>
15+
<h6 class="mb-1">
16+
<a href="/blog/{{ $blog->slug }}" class="text-decoration-none">
17+
{{ $blog->title }}
18+
</a>
19+
</h6>
20+
<small class="text-muted">{{ $blog->created_at?->format('M d, Y') }}</small>
21+
</div>
22+
</div>
23+
</div>
24+
@endforeach
25+
</div>
26+
</div>

src/Facades/Blog.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Coderstm\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
/**
8+
* @method static \Coderstm\Models\Blog|null current()
9+
* @method static mixed get($key, $default = null)
10+
* @method static \Coderstm\Models\Blog|null find($id)
11+
* @method static \Coderstm\Models\Blog|null findBySlug($slug)
12+
* @method static \Illuminate\Database\Eloquent\Collection recent($limit = 5)
13+
* @method static \Illuminate\Database\Eloquent\Collection related($blog = null, $limit = 3)
14+
* @method static \Illuminate\Database\Eloquent\Collection byCategory($category, $limit = 5)
15+
* @method static \Illuminate\Database\Eloquent\Collection byTag($tag, $limit = 5)
16+
* @method static \Illuminate\Support\Collection categories($onlyActive = true)
17+
* @method static \Illuminate\Support\Collection categoriesWithCount($onlyActive = true)
18+
* @method static void clearCaches()
19+
* @method static void clearBlogCache(\Coderstm\Models\Blog $blog)
20+
* @method static void clearRecentBlogCache()
21+
* @method static void clearCategoryBlogCache(string|null $category)
22+
* @method static void clearCategoryBlogCaches()
23+
* @method static void clearTagBlogCache(string|int|null $tag)
24+
* @method static void clearTagBlogCaches()
25+
*
26+
* @see \Coderstm\Services\BlogService
27+
*/
28+
class Blog extends Facade
29+
{
30+
/**
31+
* Get the registered name of the component.
32+
*
33+
* @return string
34+
*/
35+
protected static function getFacadeAccessor()
36+
{
37+
return 'blog';
38+
}
39+
}

src/Http/Controllers/Payment/GoCardlessController.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,9 @@
1111
use Coderstm\Events\GoCardless\FlowCompleted;
1212
use Coderstm\Models\PaymentMethod;
1313
use Coderstm\Services\GatewaySubscriptionFactory;
14-
use GoCardlessPro\Client as GoCardlessClient;
1514

1615
class GoCardlessController extends Controller
1716
{
18-
protected GoCardlessClient $provider;
19-
20-
function __construct()
21-
{
22-
$this->provider = Coderstm::gocardless();
23-
}
24-
2517
/**
2618
* Handle the redirect after successful GoCardless flow completion
2719
*

src/Http/Controllers/WebPageController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class WebPageController extends Controller
1313
{
1414
public $templateRoutes = [
1515
'home' => '/',
16-
'blog' => '/blogs',
16+
'blog' => '/blog',
1717
'membership' => '/membership',
1818
];
1919

@@ -38,6 +38,7 @@ public function blog(Request $request, $slug)
3838
return Blog::findBySlug($slug);
3939
});
4040

41+
// Set blog in request so it can be accessed globally
4142
$request->merge(['blog' => $blog]);
4243

4344
return $this->render($request, 'blog');

0 commit comments

Comments
 (0)