Skip to content

Commit 99eecb5

Browse files
committed
use fluent strings, add crud trait, fix blank row
1 parent d506b43 commit 99eecb5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Console/Commands/CrudModelBackpackCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,23 @@ public function handle()
106106

107107
// check if it already uses CrudTrait
108108
// if it does, do nothing
109-
if (Str::contains($content, $this->crudTrait)) {
109+
if ($content->contains($this->crudTrait)) {
110110
$this->closeProgressBlock('Already existed', 'yellow');
111111

112112
return false;
113113
} else {
114-
$modifiedContent = Str::of(Str::before($content, ';'))
114+
$modifiedContent = Str::of($content->before(';'))
115115
->append(';'.PHP_EOL.PHP_EOL.'use Backpack\CRUD\app\Models\Traits\CrudTrait;');
116116

117117
$content = $content->after(';');
118118

119-
$hasNewLine = str_starts_with($content, '\n') ? 1 : 0;
119+
$hasNewLine = str_starts_with($content, '\n\n') ? 1 : 0;
120120

121121
$modifiedContent = $modifiedContent->append(substr($content, strpos($content, "\n") + $hasNewLine));
122122

123+
// use the CrudTrait on the class
124+
$modifiedContent = $modifiedContent->replaceFirst('{', '{'.PHP_EOL.' use CrudTrait;');
125+
123126
// save the file
124127
$this->files->put($path, $modifiedContent);
125128
// let the user know what we've done

0 commit comments

Comments
 (0)