2
2
3
3
namespace Statikbe \FilamentFlexibleContentBlockPages \Listeners ;
4
4
5
+ use Illuminate \Http \Response ;
5
6
use Statikbe \FilamentFlexibleContentBlockPages \Models \Page ;
6
7
use Statikbe \FilamentFlexibleContentBlockPages \Models \Redirect ;
7
- use Illuminate \Http \Response ;
8
8
use Statikbe \FilamentFlexibleContentBlocks \Events \SlugChanged ;
9
9
10
10
/**
@@ -14,31 +14,30 @@ class SlugChangedListener
14
14
{
15
15
public function handle (SlugChanged $ event ): void
16
16
{
17
- //add redirect:
18
- if ($ event ->recordWasPublished ) {
19
- foreach ($ event ->changedSlugs as $ changedSlug ){
17
+ // add redirect:
18
+ if ($ event ->recordWasPublished ) {
19
+ foreach ($ event ->changedSlugs as $ changedSlug ) {
20
20
$ oldUrl = null ;
21
21
$ newUrl = null ;
22
22
23
- if ($ changedSlug ['newSlug ' ] && !empty (trim ($ changedSlug ['newSlug ' ]))) {
23
+ if ($ changedSlug ['newSlug ' ] && ! empty (trim ($ changedSlug ['newSlug ' ]))) {
24
24
if ($ event ->record instanceof Page) {
25
25
26
26
$ oldUrl = $ this ->getUrl ($ event ->record , $ changedSlug ['locale ' ], $ changedSlug ['oldSlug ' ]);
27
27
$ newUrl = $ this ->getUrl ($ event ->record , $ changedSlug ['locale ' ], $ changedSlug ['newSlug ' ]);
28
28
}
29
29
}
30
30
31
-
32
- if ($ newUrl && $ oldUrl ){
31
+ if ($ newUrl && $ oldUrl ) {
33
32
$ oldUrlPath = parse_url ($ oldUrl , PHP_URL_PATH );
34
33
$ newUrlPath = parse_url ($ newUrl , PHP_URL_PATH );
35
34
36
35
$ redirectDoesNotExist = Redirect::where ('old_url ' , $ oldUrlPath )
37
36
->where ('new_url ' , $ newUrlPath )
38
37
->notExists ();
39
38
40
- if ($ redirectDoesNotExist ) {
41
- $ redirect = new Redirect () ;
39
+ if ($ redirectDoesNotExist ) {
40
+ $ redirect = new Redirect ;
42
41
$ redirect ->old_url = $ oldUrlPath ;
43
42
$ redirect ->new_url = $ newUrlPath ;
44
43
$ redirect ->status_code = Response::HTTP_MOVED_PERMANENTLY ;
0 commit comments