Skip to content

Commit 3822dfb

Browse files
authored
Merge pull request #21 from PrintNow/feat/laravel-13-compatibility
feat: 兼容 Laravel 13
2 parents b382148 + 7bf7d84 commit 3822dfb

5 files changed

Lines changed: 11 additions & 19 deletions

File tree

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "printnow/laravel-admin",
3-
"description": "Dcat admin 永久分叉版 / 支持 Laravel 12, PHP 版本限制 >= 8.1(支持 PHP 8.4",
3+
"description": "Dcat admin 永久分叉版 / 支持 Laravel 10-13, PHP 版本限制 >= 8.1(支持 PHP 8.5",
44
"type": "library",
55
"keywords": [
66
"dcat",
@@ -25,9 +25,8 @@
2525
],
2626
"require": {
2727
"php": ">=8.1",
28-
"laravel/framework": "~10.0|~11.0|~12.0",
29-
"spatie/eloquent-sortable": "4.*",
30-
"doctrine/dbal": "~3.0|~4.0",
28+
"laravel/framework": "~10.0|~11.0|~12.0|~13.0",
29+
"spatie/eloquent-sortable": "^4.0|^5.0",
3130
"ext-dom": "*",
3231
"ext-fileinfo": "*",
3332
"ext-zip": "*",
@@ -36,7 +35,7 @@
3635
"require-dev": {
3736
"laravel/dusk": "^8.3",
3837
"phpstan/phpstan": "^2.1",
39-
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
38+
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0 || ^13.0",
4039
"fakerphp/faker": "^1.24",
4140
"mockery/mockery": "^1.6"
4241
},

src/Console/ExportSeedCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function handle()
3232
$exceptFields = [];
3333
$exportUsers = $this->option('users');
3434

35-
$namespace = version_compare(app()->version(), '8.0.0', '<') ? 'seeds' : 'seeders';
35+
$namespace = 'seeders';
3636

3737
$seedFile = $this->laravel->databasePath().'/'.$namespace.'/'.$name.'.php';
3838
$contents = $this->getStub('AdminTablesSeeder');

src/Repositories/EloquentRepository.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,9 @@ protected function joinParameters(Relation $relation)
324324
$relatedTable = $relation->getRelated()->getTable();
325325

326326
if ($relation instanceof BelongsTo) {
327-
$foreignKeyMethod = version_compare(app()->version(), '5.8.0', '<') ? 'getForeignKey' : 'getForeignKeyName';
328-
329327
return [
330328
$relatedTable,
331-
$relation->{$foreignKeyMethod}(),
329+
$relation->getForeignKeyName(),
332330
'=',
333331
$relatedTable.'.'.$relation->getRelated()->getKeyName(),
334332
];
@@ -872,9 +870,8 @@ protected function updateRelation(Form $form, EloquentModel $model, array $relat
872870
$parent->save();
873871

874872
// When in creating, associate two models
875-
$foreignKeyMethod = version_compare(app()->version(), '5.8.0', '<') ? 'getForeignKey' : 'getForeignKeyName';
876-
if (! $model->{$relation->{$foreignKeyMethod}()}) {
877-
$model->{$relation->{$foreignKeyMethod}()} = $parent->getKey();
873+
if (! $model->{$relation->getForeignKeyName()}) {
874+
$model->{$relation->getForeignKeyName()} = $parent->getKey();
878875

879876
$model->save();
880877
}

src/Scaffold/ModelCreator.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,8 @@ protected function replaceSoftDeletes(&$stub, $softDeletes)
171171
*/
172172
protected function replaceDatetimeFormatter(&$stub)
173173
{
174-
$import = $use = '';
175-
176-
if (version_compare(app()->version(), '7.0.0') >= 0) {
177-
$import = 'use Dcat\\Admin\\Traits\\HasDateTimeFormatter;';
178-
$use = 'use HasDateTimeFormatter;';
179-
}
174+
$import = 'use Dcat\\Admin\\Traits\\HasDateTimeFormatter;';
175+
$use = 'use HasDateTimeFormatter;';
180176

181177
$stub = str_replace(['DummyImportDateTimeFormatterTrait', 'DummyUseDateTimeFormatterTrait'], [$import, $use], $stub);
182178

src/Support/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function trans($key, array $replace = [], $locale = null)
110110
protected function getTranslateMethod()
111111
{
112112
if (static::$method === null) {
113-
static::$method = version_compare(app()->version(), '6.0', '>=') ? 'get' : 'trans';
113+
static::$method = 'get';
114114
}
115115

116116
return static::$method;

0 commit comments

Comments
 (0)