22
33namespace Statikbe \FilamentFlexibleContentBlockPages \Listeners ;
44
5+ use Illuminate \Http \Response ;
56use Statikbe \FilamentFlexibleContentBlockPages \Models \Page ;
67use Statikbe \FilamentFlexibleContentBlockPages \Models \Redirect ;
7- use Illuminate \Http \Response ;
88use Statikbe \FilamentFlexibleContentBlocks \Events \SlugChanged ;
99
1010/**
@@ -14,31 +14,30 @@ class SlugChangedListener
1414{
1515 public function handle (SlugChanged $ event ): void
1616 {
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 ) {
2020 $ oldUrl = null ;
2121 $ newUrl = null ;
2222
23- if ($ changedSlug ['newSlug ' ] && !empty (trim ($ changedSlug ['newSlug ' ]))) {
23+ if ($ changedSlug ['newSlug ' ] && ! empty (trim ($ changedSlug ['newSlug ' ]))) {
2424 if ($ event ->record instanceof Page) {
2525
2626 $ oldUrl = $ this ->getUrl ($ event ->record , $ changedSlug ['locale ' ], $ changedSlug ['oldSlug ' ]);
2727 $ newUrl = $ this ->getUrl ($ event ->record , $ changedSlug ['locale ' ], $ changedSlug ['newSlug ' ]);
2828 }
2929 }
3030
31-
32- if ($ newUrl && $ oldUrl ){
31+ if ($ newUrl && $ oldUrl ) {
3332 $ oldUrlPath = parse_url ($ oldUrl , PHP_URL_PATH );
3433 $ newUrlPath = parse_url ($ newUrl , PHP_URL_PATH );
3534
3635 $ redirectDoesNotExist = Redirect::where ('old_url ' , $ oldUrlPath )
3736 ->where ('new_url ' , $ newUrlPath )
3837 ->notExists ();
3938
40- if ($ redirectDoesNotExist ) {
41- $ redirect = new Redirect () ;
39+ if ($ redirectDoesNotExist ) {
40+ $ redirect = new Redirect ;
4241 $ redirect ->old_url = $ oldUrlPath ;
4342 $ redirect ->new_url = $ newUrlPath ;
4443 $ redirect ->status_code = Response::HTTP_MOVED_PERMANENTLY ;
0 commit comments