File tree Expand file tree Collapse file tree 3 files changed +66
-1
lines changed Expand file tree Collapse file tree 3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 19
19
"php" : " ^8.4" ,
20
20
"spatie/laravel-package-tools" : " ^1.16" ,
21
21
"illuminate/contracts" : " ^10.0||^11.0||^12.0" ,
22
- "statikbe/laravel-filament-flexible-content-blocks" : " ^2.4"
22
+ "statikbe/laravel-filament-flexible-content-blocks" : " ^2.4" ,
23
+ "spatie/laravel-missing-page-redirector" : " ^2.11"
23
24
},
24
25
"require-dev" : {
25
26
"laravel/pint" : " ^1.14" ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Illuminate\Database\Migrations\Migration;
4
+ use Illuminate\Database\Schema\Blueprint;
5
+ use Illuminate\Support\Facades\Schema;
6
+
7
+ return new class extends Migration {
8
+ public function up()
9
+ {
10
+ Schema::create('redirects', function (Blueprint $table) {
11
+ $table->id();
12
+ $table->string('old_url');
13
+ $table->string('new_url');
14
+ $table->integer('status_code')->nullable();
15
+ $table->timestamps();
16
+ });
17
+ }
18
+ };
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Statikbe \FilamentFlexibleContentBlockPages \Models ;
4
+
5
+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
6
+ use Illuminate \Database \Eloquent \Model ;
7
+ use Illuminate \Support \Facades \Cache ;
8
+
9
+ /**
10
+ * TODO observer
11
+ * @see RedirectObserver for clearing the cache.
12
+ */
13
+ class Redirect extends Model
14
+ {
15
+ use HasFactory;
16
+
17
+ const CACHE_REDIRECTS_KEY = 'filament-flexible-content-block-pages:redirects ' ;
18
+
19
+ protected $ guarded = ['id ' ];
20
+
21
+ /**
22
+ * Returns a list of old and new urls with the status code if set compatible with spatie/laravel-missing-page-redirector,
23
+ * that merges the redirects set in the database over the redirects set in the config.
24
+ * @return array
25
+ */
26
+ public static function getDirectionMap (): array {
27
+ // Get from the database and remember forever
28
+ // we clear this on new model or updated model
29
+ $ dbRedirects = Cache::rememberForever (static ::CACHE_REDIRECTS_KEY , function () {
30
+ return Redirect::all ()->flatMap (function (Redirect $ redirect ) {
31
+ if ($ redirect ->status_code ){
32
+ return [
33
+ $ redirect ->old_url => [$ redirect ->new_url , $ redirect ->status_code ]
34
+ ];
35
+ }
36
+ else return [$ redirect ->old_url => $ redirect ->new_url ];
37
+ })->toArray ();
38
+ });
39
+
40
+ // Get the redirects from the config
41
+ $ configRedirects = config ('missing-page-redirector.redirects ' );
42
+
43
+ // Merge both values
44
+ return array_merge ($ configRedirects , $ dbRedirects );
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments