Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/Commands/Make/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function handle(): int
$this->handleOptionalRequestOption();
$this->handleOptionalResourceOption();
$this->handleOptionalSeedOption();
$this->handleOptionalPolicyOption();

return 0;
}
Expand Down Expand Up @@ -194,6 +195,21 @@ protected function handleOptionalSeedOption(): void
}
}

/**
* Create a policy file for the model.
*/
protected function handleOptionalPolicyOption(): void
{
if($this->option('policy') === true) {
$policyName = "{$this->getModelName()}Policy";

$this->call('module:make-policy', array_filter([
'name' => $policyName,
'module' => $this->argument('module'),
]));
}
}

protected function getTemplateContents(): string
{
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
Expand Down
12 changes: 12 additions & 0 deletions tests/Commands/Make/ModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,16 @@ public function test_it_can_change_the_default_namespace_specific()
$this->assertMatchesSnapshot($file);
$this->assertSame(0, $code);
}

public function test_it_generates_policy_file_with_model()
{
$code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--policy' => true]);

$policies = $this->finder->allFiles($this->modulePath.'/Policies');
$policyFile = $policies[0];
$policyContent = $this->finder->get($this->modulePath.'/Policies/'.$policyFile->getFilename());
$this->assertCount(1, $policies);
$this->assertMatchesSnapshot($policyContent);
$this->assertSame(0, $code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Modules\Blog\Policies;

use Illuminate\Auth\Access\HandlesAuthorization;

class PostPolicy
{
use HandlesAuthorization;

/**
* Create a new policy instance.
*/
public function __construct() {}
}