Created
January 13, 2021 20:54
-
-
Save morrislaptop/f8c0ab355bcf563fb623e6f5da9e5808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Support; | |
use Blueprint\Models\Model; | |
use Illuminate\Support\Str; | |
use Blueprint\Generators\ModelGenerator as BaseModelGenerator; | |
class ModelGenerator extends BaseModelGenerator | |
{ | |
protected function populateStub(string $stub, Model $model) | |
{ | |
$stub = parent::populateStub($stub, $model); | |
if ($model->name() === 'User') { | |
$stub = Str::replaceFirst('extends Model', 'extends \Illuminate\Foundation\Auth\User', $stub); | |
} | |
if ($model->name() === 'Team') { | |
$stub = Str::replaceFirst('extends Model', 'extends \Laravel\Jetstream\Team', $stub); | |
} | |
return $stub; | |
} | |
protected function addTraits(Model $model, $stub) | |
{ | |
$stub = parent::addTraits($model, $stub); | |
$behaviour = "{$model->name()}Behaviour"; | |
if (trait_exists("App\Models\\$behaviour")) { | |
$stub = Str::replaceFirst('use HasFactory', "use HasFactory, $behaviour", $stub); | |
} | |
return $stub; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment