Skip to content

Instantly share code, notes, and snippets.

@morrislaptop
Created January 13, 2021 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morrislaptop/f8c0ab355bcf563fb623e6f5da9e5808 to your computer and use it in GitHub Desktop.
Save morrislaptop/f8c0ab355bcf563fb623e6f5da9e5808 to your computer and use it in GitHub Desktop.
<?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