Skip to content

Commit 1f29e16

Browse files
authored
Merge pull request #9 from novius/feature/use_laravel_meta
Refactoring to use laravel-meta
2 parents 5475533 + e686836 commit 1f29e16

14 files changed

+214
-188
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# [6.0.0]
2+
3+
In this version, the page manager introduces the use of the `laravel-meta` library.
4+
5+
Read the [documentation](https://github.com/novius/laravel-meta) of this package
6+
7+
## Breaking Change
8+
9+
* Run migrations
10+
* Modify the Page controller and Page templates as describe in the documentation (https://github.com/novius/laravel-meta?tab=readme-ov-file#front)
11+
112
# [4.0.0]
213

314
In this version, the page manager introduces the use of the `laravel-nova-publishable` and `laravel-nova-translatable` libraries.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ php artisan page-manager:publish-front
4343

4444
This command appends a route to `routes/web.php` and creates a new `App\Http\Controllers\FrontPageController`.
4545

46+
In Page templates use the documentation of [laravel-meta](https://github.com/novius/laravel-meta?tab=readme-ov-file#front) to implement meta tags
47+
4648
## Configuration
4749

4850
Some options that you can override are available.
@@ -128,7 +130,7 @@ composer run-script lint
128130

129131
Contributions are welcome!
130132

131-
Leave an issue on Github, or create a Pull Request.
133+
Leave an issue on GitHub, or create a Pull Request.
132134

133135
## Licence
134136

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"php": ">=8.2",
1919
"illuminate/support": "^10.0|^11.0",
2020
"laravel/nova": "^4.0",
21+
"novius/laravel-meta": "^1.0",
2122
"novius/laravel-nova-field-preview": "^2.0",
2223
"novius/laravel-nova-publishable": "^3.0",
2324
"novius/laravel-nova-translatable": "^1.0",
@@ -55,6 +56,6 @@
5556
"config": {
5657
"sort-packages": true
5758
},
58-
"minimum-stability": "dev",
59+
"minimum-stability": "stable",
5960
"prefer-stable": true
6061
}

config/laravel-nova-page-manager.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22

3+
use Novius\LaravelNovaPageManager\Resources\Page;
4+
use Novius\LaravelNovaPageManager\Templates\DefaultTemplate;
5+
36
return [
47

58
'resources' => [
6-
\Novius\LaravelNovaPageManager\Resources\Page::class,
9+
Page::class,
710
],
811

912
'locales' => [
@@ -21,6 +24,6 @@
2124
'guard_preview' => null,
2225

2326
'templates' => [
24-
\Novius\LaravelNovaPageManager\Templates\DefaultTemplate::class,
27+
DefaultTemplate::class,
2528
],
2629
];

database/migrations/2020_10_08_082811_page_manager_create_pages_table.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('page_manager_pages', function (Blueprint $table) {
14+
Schema::create('page_manager_pages', static function (Blueprint $table) {
1515
$table->id();
1616

1717
$table->string('title', 191);
@@ -28,8 +28,7 @@ public function up(): void
2828

2929
$table->string('seo_title');
3030
$table->string('seo_description');
31-
$table->unsignedTinyInteger('seo_robots')
32-
->default(\Novius\LaravelNovaPageManager\Models\Page::ROBOTS_INDEX_FOLLOW);
31+
$table->unsignedTinyInteger('seo_robots')->default(1);
3332
$table->string('seo_canonical_url')->nullable();
3433

3534
$table->string('og_title')->nullable();

database/migrations/2023_07_10_170415_alter_page_manager_add_publishable_fields.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{
1111
public function up(): void
1212
{
13-
Schema::table('page_manager_pages', function (Blueprint $table) {
13+
Schema::table('page_manager_pages', static function (Blueprint $table) {
1414
$table->enum('publication_status', array_column(PublicationStatus::cases(), 'value'))
1515
->default(PublicationStatus::draft->value)
1616
->after('locale_parent_id');
@@ -37,14 +37,14 @@ public function up(): void
3737
DB::statement('UPDATE page_manager_pages SET publication_status = ?, published_first_at = created_at, expired_at = end_publication_date
3838
WHERE publication_date IS NULL AND end_publication_date IS NOT NULL', [PublicationStatus::unpublished->value]);
3939

40-
Schema::table('page_manager_pages', function (Blueprint $table) {
40+
Schema::table('page_manager_pages', static function (Blueprint $table) {
4141
$table->dropColumn(['publication_date', 'end_publication_date']);
4242
});
4343
}
4444

4545
public function down(): void
4646
{
47-
Schema::table('page_manager_pages', function (Blueprint $table) {
47+
Schema::table('page_manager_pages', static function (Blueprint $table) {
4848
$table->dateTime('publication_date')->nullable()->after('locale_parent_id');
4949
$table->dateTime('end_publication_date')->nullable()->after('publication_date');
5050
});
@@ -58,7 +58,7 @@ public function down(): void
5858
DB::statement('UPDATE page_manager_pages SET publication_date = null, end_publication_date = expired_at
5959
WHERE publication_status = ?', [PublicationStatus::unpublished->value]);
6060

61-
Schema::table('page_manager_pages', function (Blueprint $table) {
61+
Schema::table('page_manager_pages', static function (Blueprint $table) {
6262
$table->dropPublishable();
6363
});
6464
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
use Novius\LaravelMeta\Enums\IndexFollow;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::table('page_manager_pages', static function (Blueprint $table) {
14+
$table->addMeta();
15+
});
16+
17+
DB::table('page_manager_pages')->orderBy('id')->chunk(100, function ($pages) {
18+
foreach ($pages as $page) {
19+
$meta = [
20+
'seo_robots' => match ($page->seo_robots) {
21+
1 => IndexFollow::index_follow->value,
22+
2 => IndexFollow::index_nofollow->value,
23+
3 => IndexFollow::noindex_nofollow->value,
24+
4 => IndexFollow::noindex_follow->value,
25+
},
26+
'seo_title' => $page->seo_title,
27+
'seo_description' => $page->seo_description,
28+
'seo_canonical_url' => $page->seo_canonical_url,
29+
'og_title' => $page->og_title,
30+
'og_description' => $page->og_description,
31+
'og_image' => $page->og_image,
32+
];
33+
DB::table('page_manager_pages')->where('id', $page->id)->update([
34+
'meta' => json_encode($meta, JSON_THROW_ON_ERROR),
35+
]);
36+
}
37+
});
38+
39+
Schema::table('page_manager_pages', static function (Blueprint $table) {
40+
$table->dropColumn([
41+
'seo_robots',
42+
'seo_title',
43+
'seo_description',
44+
'seo_canonical_url',
45+
'og_title',
46+
'og_description',
47+
'og_image',
48+
]);
49+
});
50+
}
51+
52+
public function down(): void
53+
{
54+
Schema::table('page_manager_pages', static function (Blueprint $table) {
55+
$table->string('seo_title');
56+
$table->string('seo_description');
57+
$table->unsignedTinyInteger('seo_robots')->default(1);
58+
$table->string('seo_canonical_url')->nullable();
59+
60+
$table->string('og_title')->nullable();
61+
$table->string('og_description')->nullable();
62+
$table->string('og_image')->nullable();
63+
});
64+
65+
DB::table('page_manager_pages')->orderBy('id')->chunk(100, function ($pages) {
66+
foreach ($pages as $page) {
67+
$meta = json_decode($page->meta, false, 512, JSON_THROW_ON_ERROR);
68+
DB::table('page_manager_pages')->where('id', $page->id)->update([
69+
'seo_robots' => $meta->seo_robots ?? 1,
70+
'seo_title' => $meta->seo_title ?? null,
71+
'seo_description' => $meta->seo_description ?? null,
72+
'seo_canonical_url' => $page->seo_canonical_url ?? null,
73+
'og_title' => $meta->og_title ?? null,
74+
'og_description' => $meta->og_description ?? null,
75+
'og_image' => $meta->og_image ?? null,
76+
]);
77+
}
78+
});
79+
80+
Schema::table('page_manager_pages', static function (Blueprint $table) {
81+
$table->dropColumn('meta');
82+
});
83+
}
84+
};

resources/views/navigation.blade.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Console/FrontControllerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FrontControllerCommand extends GeneratorCommand
2727
*/
2828
protected $type = 'Controller';
2929

30-
public function handle()
30+
public function handle(): void
3131
{
3232
if (parent::handle() !== false) {
3333
if (! is_file(base_path('routes/web.php'))) {

src/Console/stubs/controller.front.stub

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,18 @@
33
namespace {{ namespace }};
44

55
use Illuminate\Http\Request;
6+
use Novius\LaravelMeta\Facades\CurrentModel;
67
use Novius\LaravelNovaPageManager\Models\Page;
78

89
class {{ class }} extends Controller
910
{
1011
/**
1112
* Handle the incoming request.
12-
*
13-
* @param \Illuminate\Http\Request $request
14-
* @param string $slug
15-
* @return \Illuminate\Http\Response
1613
*/
17-
public function __invoke(Request $request, string $slug)
14+
public function __invoke(Page $page)
1815
{
19-
$locale = app()->getLocale();
20-
$page = Page::where('slug', $slug)->where('locale', $locale)->first();
21-
if (empty($page)) {
22-
abort(404);
23-
}
24-
/**
25-
* @var Page $page
26-
*/
27-
if (!$page->isPublished()) {
28-
$token = (string)$request->get('previewToken', '');
29-
if ($token !== $page->preview_token) {
30-
abort(403);
31-
}
32-
}
16+
CurrentModel::setModel($page);
3317

34-
return sprintf('PAGE %d', $page->id);
18+
return view('pages.'.$page->template, ['page' => $page]);
3519
}
3620
}

0 commit comments

Comments
 (0)