Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private function addTraits(Model $model, $stub)
}

$stub = str_replace('use Illuminate\\Database\\Eloquent\\Model;', 'use Illuminate\\Database\\Eloquent\\Model;' . PHP_EOL . 'use Illuminate\\Database\\Eloquent\\SoftDeletes;', $stub);
$stub = str_replace('{', '{' . PHP_EOL . ' use SoftDeletes;' . PHP_EOL, $stub);
$stub = preg_replace('/^\\{$/m', '{' . PHP_EOL . ' use SoftDeletes;' . PHP_EOL, $stub);

return $stub;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/Generator/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function output_writes_migration_for_model_tree($definition, $path, $mode
->with('stubs/model/class.stub')
->andReturn(file_get_contents('stubs/model/class.stub'));

// TODO: remove conditional expectations
if ($iteration === 0) {
$this->files->expects('get')
->with('stubs/model/fillable.stub')
Expand All @@ -67,7 +68,7 @@ public function output_writes_migration_for_model_tree($definition, $path, $mode
->andReturn(file_get_contents('stubs/model/dates.stub'));
}

if ($definition === 'definitions/relationships.bp') {
if ($definition === 'definitions/soft-deletes.bp') {
$this->files->expects('get')
->with('stubs/model/method.stub')
->andReturn(file_get_contents('stubs/model/method.stub'));
Expand All @@ -88,8 +89,8 @@ public function modelTreeDataProvider()
{
return [
['definitions/readme-example.bp', 'app/Post.php', 'models/readme-example.php'],
['definitions/with-timezones.bp', 'app/Comment.php', 'models/comment.php'],
['definitions/soft-deletes.bp', 'app/Comment.php', 'models/soft-deletes.php'],
['definitions/with-timezones.bp', 'app/Comment.php', 'models/soft-deletes.php'],
['definitions/relationships.bp', 'app/Comment.php', 'models/relationships.php'],
];
}
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/definitions/soft-deletes.bp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
models:
Comment:
post_id: id
softdeletes
1 change: 1 addition & 0 deletions tests/fixtures/migrations/soft-deletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->unsignedBigInteger('post_id');
$table->softDeletes();
$table->timestamps();
});
Expand Down
27 changes: 27 additions & 0 deletions tests/fixtures/models/comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Comment extends Model
{
use SoftDeletes;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
];
}
11 changes: 10 additions & 1 deletion tests/fixtures/models/soft-deletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class Comment extends Model
*
* @var array
*/
protected $fillable = [];
protected $fillable = [
'post_id',
];

/**
* The attributes that should be cast to native types.
Expand All @@ -23,5 +25,12 @@ class Comment extends Model
*/
protected $casts = [
'id' => 'integer',
'post_id' => 'integer',
];


public function post()
{
return $this->belongsTo(\App\Post::class);
}
}