@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | public static function findBySlug(string $slug, string $locale): UrlRecord |
23 | 23 | { |
24 | 24 | // Clear the input from any trailing slashes. |
25 | - if($slug != '/'){ $slug = trim($slug,'/'); } |
|
25 | + if ($slug != '/') { $slug = trim($slug, '/'); } |
|
26 | 26 | |
27 | 27 | $record = static::where('slug', $slug) |
28 | 28 | ->where('locale', $locale) |
29 | 29 | ->orderBy('redirect_id', 'ASC') |
30 | 30 | ->first(); |
31 | 31 | |
32 | - if(!$record){ |
|
32 | + if (!$record) { |
|
33 | 33 | throw new UrlRecordNotFound('No url record found by slug ['.$slug.'] for locale ['.$locale.'].'); |
34 | 34 | } |
35 | 35 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ->orderBy('redirect_id', 'ASC') |
54 | 54 | ->first(); |
55 | 55 | |
56 | - if(!$record){ |
|
56 | + if (!$record) { |
|
57 | 57 | throw new UrlRecordNotFound('No url record found for model ['.$model->getMorphClass().'@'.$model->id.'] for locale ['.$locale.'].'); |
58 | 58 | } |
59 | 59 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | public function redirectTo(self $record = null): ?UrlRecord |
84 | 84 | { |
85 | - if(!$record){ |
|
85 | + if (!$record) { |
|
86 | 86 | return $this->isRedirect() ? static::find($this->redirect_id) : null; |
87 | 87 | } |
88 | 88 | |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | { |
107 | 107 | $builder = static::where('slug', $slug); |
108 | 108 | |
109 | - if($locale) { |
|
109 | + if ($locale) { |
|
110 | 110 | $builder->where('locale', $locale); |
111 | 111 | } |
112 | 112 | |
113 | - if( ! $includeRedirects){ |
|
113 | + if (!$includeRedirects) { |
|
114 | 114 | $builder->whereNull('redirect_id'); |
115 | 115 | } |
116 | 116 | |
117 | - if($ignoredModel){ |
|
117 | + if ($ignoredModel) { |
|
118 | 118 | $builder->whereNotIn('id', function($query) use($ignoredModel){ |
119 | 119 | $query->select('id') |
120 | 120 | ->from('chief_urls') |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | { |
22 | 22 | $this->existingRecords = UrlRecord::getByModel($this->model); |
23 | 23 | |
24 | - foreach($slugs as $locale => $slug){ |
|
24 | + foreach ($slugs as $locale => $slug) { |
|
25 | 25 | |
26 | - if(!$slug){ |
|
26 | + if (!$slug) { |
|
27 | 27 | $this->deleteRecord($locale); |
28 | 28 | continue; |
29 | 29 | } |
@@ -52,21 +52,21 @@ discard block |
||
52 | 52 | $this->deleteIdenticalRedirects($this->existingRecords, $locale, $slug); |
53 | 53 | |
54 | 54 | // Also delete any redirects that match this locale and slug but are related to another model |
55 | - $this->deleteIdenticalRedirects(UrlRecord::where('slug',$slug)->where('locale',$locale)->get(), $locale, $slug); |
|
55 | + $this->deleteIdenticalRedirects(UrlRecord::where('slug', $slug)->where('locale', $locale)->get(), $locale, $slug); |
|
56 | 56 | |
57 | 57 | // If slug entry is left empty, all existing records will be deleted |
58 | - if(!$slug){ |
|
59 | - $nonRedirectsWithSameLocale->each(function($existingRecord){ |
|
58 | + if (!$slug) { |
|
59 | + $nonRedirectsWithSameLocale->each(function($existingRecord) { |
|
60 | 60 | $existingRecord->delete(); |
61 | 61 | }); |
62 | 62 | } |
63 | - elseif($nonRedirectsWithSameLocale->isEmpty()){ |
|
63 | + elseif ($nonRedirectsWithSameLocale->isEmpty()) { |
|
64 | 64 | $this->createRecord($locale, $slug); |
65 | 65 | } |
66 | - else{ |
|
66 | + else { |
|
67 | 67 | // Only replace the existing records that differ from the current passed slugs |
68 | 68 | $nonRedirectsWithSameLocale->each(function($existingRecord) use($slug){ |
69 | - if($existingRecord->slug != $slug){ |
|
69 | + if ($existingRecord->slug != $slug) { |
|
70 | 70 | $existingRecord->replaceAndRedirect(['slug' => $slug]); |
71 | 71 | } |
72 | 72 | }); |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function deleteIdenticalRedirects($existingRecords, $locale, $slug): void |
92 | 92 | { |
93 | - $existingRecords->filter(function ($record) use ($locale) { |
|
93 | + $existingRecords->filter(function($record) use ($locale) { |
|
94 | 94 | return ( |
95 | 95 | $record->locale == $locale && |
96 | 96 | $record->isRedirect() |
97 | 97 | ); |
98 | - })->each(function ($existingRecord) use ($slug) { |
|
98 | + })->each(function($existingRecord) use ($slug) { |
|
99 | 99 | if ($existingRecord->slug == $slug) { |
100 | 100 | $existingRecord->delete(); |
101 | 101 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | private function prependBaseUrlSegment(string $slug, $locale): string |
111 | 111 | { |
112 | - $slugWithBaseSegment = $this->model->baseUrlSegment($locale) . '/' . $slug; |
|
112 | + $slugWithBaseSegment = $this->model->baseUrlSegment($locale).'/'.$slug; |
|
113 | 113 | $slugWithBaseSegment = trim($slugWithBaseSegment, '/'); |
114 | 114 | |
115 | 115 | // If slug with base segment is empty string, it means that the passed slug was probably a "/" character. |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | { |
26 | 26 | $array = []; |
27 | 27 | |
28 | - foreach($this->all() as $field) { |
|
28 | + foreach ($this->all() as $field) { |
|
29 | 29 | $array[] = $field->toArray(); |
30 | 30 | } |
31 | 31 | |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | $fields = new static([]); |
43 | 43 | |
44 | 44 | foreach ($locales as $locale) { |
45 | - $fields['url-slugs.' . $locale] = UrlSlugField::make('url-slugs.' . $locale) |
|
45 | + $fields['url-slugs.'.$locale] = UrlSlugField::make('url-slugs.'.$locale) |
|
46 | 46 | ->setBaseUrlSegment($model->baseUrlSegment($locale)) |
47 | - ->prepend($model->resolveUrl($locale, $model->baseUrlSegment($locale)) .'/') |
|
48 | - ->name('url-slugs[' . $locale . ']') |
|
49 | - ->label($locale . ' link'); |
|
47 | + ->prepend($model->resolveUrl($locale, $model->baseUrlSegment($locale)).'/') |
|
48 | + ->name('url-slugs['.$locale.']') |
|
49 | + ->label($locale.' link'); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $fields; |
@@ -58,18 +58,18 @@ discard block |
||
58 | 58 | */ |
59 | 59 | private static function fillWithExistingValues(ProvidesUrl $model, self $fields): void |
60 | 60 | { |
61 | - $records = MemoizedUrlRecord::getByModel($model)->reject(function ($record) { |
|
61 | + $records = MemoizedUrlRecord::getByModel($model)->reject(function($record) { |
|
62 | 62 | return $record->isRedirect(); |
63 | 63 | })->sortBy('locale'); |
64 | 64 | |
65 | 65 | foreach ($records as $record) { |
66 | 66 | |
67 | - if(!isset($fields['url-slugs.'.$record->locale])) continue; |
|
67 | + if (!isset($fields['url-slugs.'.$record->locale])) continue; |
|
68 | 68 | |
69 | 69 | $fields['url-slugs.'.$record->locale] |
70 | 70 | ->setUrlRecord($record) |
71 | 71 | ->setBaseUrlSegment($model->baseUrlSegment($record->locale)) |
72 | - ->prepend($model->resolveUrl($record->locale, $model->baseUrlSegment($record->locale)) .'/'); |
|
72 | + ->prepend($model->resolveUrl($record->locale, $model->baseUrlSegment($record->locale)).'/'); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -27,7 +27,7 @@ |
||
27 | 27 | */ |
28 | 28 | public function passes($attribute, $slugs) |
29 | 29 | { |
30 | - foreach($slugs as $locale => $slug) { |
|
30 | + foreach ($slugs as $locale => $slug) { |
|
31 | 31 | if (UrlRecord::existsIgnoringRedirects($slug, $locale, $this->ignoredModel)) { |
32 | 32 | session()->flash('unique_url_slug_validation', [ |
33 | 33 | 'locale' => $locale, |