Skip to content

Commit

Permalink
Fix deferred provider
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-de-wit committed Jan 31, 2025
1 parent 2f05c17 commit b23ac84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/Hooks/TranslatableHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
use Astrotomic\Translatable\Contracts\Translatable;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;

class TranslatableHook implements ModelHookInterface
{
public function run(ModelsCommand $command, Model $model): void
{
if (
! $model instanceof Translatable ||
! method_exists($model, 'getTranslationModelName') ||
! property_exists($model, 'translatedAttributes')
! $model instanceof Translatable || ! method_exists($model, 'getTranslationModelName') || ! property_exists($model, 'translatedAttributes')
) {
return;
}
Expand All @@ -28,7 +24,7 @@ public function run(ModelsCommand $command, Model $model): void
/** @var Model $modelTranslation */
$modelTranslation = $command->getLaravel()->make($className);

$table = $modelTranslation->getConnection()->getTablePrefix() . $modelTranslation->getTable();
$table = $modelTranslation->getConnection()->getTablePrefix().$modelTranslation->getTable();

$columns = $modelTranslation->getConnection()->getSchemaBuilder()->getColumns($table);

Expand Down Expand Up @@ -97,4 +93,11 @@ public function run(ModelsCommand $command, Model $model): void
);
}
}

protected function getDateClass(): string
{
return class_exists(\Illuminate\Support\Facades\Date::class)
? '\\'.get_class(\Illuminate\Support\Facades\Date::now())
: '\Illuminate\Support\Carbon';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use DanielDeWit\LaravelIdeHelperHookTranslatable\Hooks\TranslatableHook;
use Illuminate\Console\Command;
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
Expand All @@ -16,10 +15,10 @@ class LaravelIdeHelperHookTranslatableServiceProvider extends ServiceProvider im
/**
* @var string
*/
const ModelsCommandAlias = 'laravel-ide-helper-hook-translatable-command-alias';
const ModelsCommandAlias = 'ModelsCommand__LaravelIdeHelperHookTranslatable__alias';

/**
* @return list<class-string<Command>|string>
* @return list<string>
*/
public function provides(): array
{
Expand Down

0 comments on commit b23ac84

Please sign in to comment.