Skip to content

Commit

Permalink
feat: add RunsArtisan Trait (#42)
Browse files Browse the repository at this point in the history
- Added RunsArtisan trait
- Update `run_by` assignment to use `getArtisanRunByName` method
  • Loading branch information
kiritokatklian authored Aug 31, 2024
1 parent 9fd5b39 commit 3b6b784
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## [4.4.0](#)
- Added `Stepanenko3\NovaCommandRunner\Traits\RunsArtisan`
- Update `run_by` assignment to use the `getArtisanRunByName` method

## [4.1.0](#)
- `Stepanenko3\NovaCommandRunner\CommandRunner` migrate to `Stepanenko3\NovaCommandRunner\CommandRunnerTool`

Expand Down
6 changes: 5 additions & 1 deletion src/Dto/RunDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class RunDto

public function __construct()
{
$this->run_by = auth()->check() ? auth()->user()->name : '';
if (auth()->check() && method_exists(auth()->user(), 'getArtisanRunByName')) {
$this->run_by = auth()->user()->getArtisanRunByName();
} else {
$this->run_by = __('unknown');
}
$this->id = uniqid();
}

Expand Down
16 changes: 16 additions & 0 deletions src/Traits/RunsArtisan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Stepanenko3\NovaCommandRunner\Traits;

trait RunsArtisan
{
/**
* The name of the user running an Artisan command.
*
* @return null|string
*/
public function getArtisanRunByName(): ?string
{
return $this->name;
}
}

0 comments on commit 3b6b784

Please sign in to comment.