Skip to content

Commit afa4e9d

Browse files
authored
feat: custom model option (#243)
1 parent 400aad8 commit afa4e9d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

config/redirect.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
'enable' => env('REDIRECT_ENABLED', true),
88

9+
/**
10+
* The model to use for redirects
11+
*/
12+
'model' => \Rias\StatamicRedirect\Eloquent\Redirects\RedirectModel::class,
13+
914
/**
1015
* Whether Redirect should automatically run database migrations or not
1116
*/

src/Eloquent/Redirects/RedirectRepository.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public function delete($entry)
9595

9696
public function query()
9797
{
98-
return new RedirectQueryBuilder(RedirectModel::query());
98+
$modelClass = config('statamic.redirect.model');
99+
return new RedirectQueryBuilder($modelClass::query());
99100
}
100101

101102
public function make(): Redirect
@@ -132,7 +133,9 @@ private function toModel(Redirect $redirect)
132133
'description' => $redirect->description(),
133134
];
134135

135-
$model = RedirectModel::firstOrNew(['id' => $redirect->id()], $properties);
136+
$modelClass = config('statamic.redirect.model');
137+
138+
$model = $modelClass::firstOrNew(['id' => $redirect->id()], $properties);
136139

137140
if ($model->exists) {
138141
$model->fill($properties);

src/UpdateScripts/IncreaseUrlSizeOnRedirects.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function update()
6666
$table->string('destination', 2048)->change();
6767
});
6868

69-
RedirectModel::each(function (RedirectModel $redirect) {
69+
$modelClass = config('statamic.redirect.model');
70+
71+
$modelClass::each(function (RedirectModel $redirect) {
7072
$redirect->update(['source_md5' => md5($redirect->source)]);
7173
});
7274

0 commit comments

Comments
 (0)