Skip to content

Commit

Permalink
Merge branch '8.x' into 9.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Jun 18, 2024
2 parents 3cd3e35 + 9bed1ce commit bed5413
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Console/UserModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Orchestra\Canvas\Console;

use Composer\InstalledVersions;
use Orchestra\Canvas\Core\Commands\GeneratorCommand;
use Orchestra\Canvas\Core\Concerns\ResolvesPresetStubs;
use Symfony\Component\Console\Attribute\AsCommand;
Expand All @@ -21,6 +22,30 @@ class UserModelMakeCommand extends GeneratorCommand
*/
protected $type = 'Model';

/**
* Build the class with the given name.
*
* @param string $name
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
#[\Override]
protected function buildClass($name)
{
$stub = parent::buildClass($name);

if (! InstalledVersions::isInstalled('laravel/sanctum')) {
$stub = str_replace(
' use HasApiTokens, HasFactory, Notifiable;'.PHP_EOL,
' use HasFactory, Notifiable;'.PHP_EOL,
$stub
);
}

return $stub;
}

/**
* Get the stub file for the generator.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Console/UserModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function it_can_generate_broadcasting_channel_file()
'namespace App\Models;',
'use Illuminate\Foundation\Auth\User as Authenticatable;',
'class User extends Authenticatable',
'use HasFactory, Notifiable;',
], 'app/Models/User.php');
}
}

0 comments on commit bed5413

Please sign in to comment.