Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] username parameter in from method should be nullable #1818

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 3 additions & 5 deletions config/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,12 @@
'webhook_url' => '',

/*
* If this is an empty string, the name field on the webhook will be used.
* If this is an empty string, the name field will be 'Laravel Backup'.
* If this is set to null, the name field on the webhook will be used.
*/
'username' => '',

/*
* If this is an empty string, the avatar on the webhook will be used.
*/
'avatar_url' => '',
'avatar_url' => null,
],
],

Expand Down
10 changes: 6 additions & 4 deletions src/Notifications/Channels/Discord/DiscordMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DiscordMessage
public const COLOR_WARNING = 'fD6a02';
public const COLOR_ERROR = 'e32929';

protected string $username = 'Laravel Backup';
protected ?string $username = null;

protected ?string $avatarUrl = null;

Expand All @@ -28,9 +28,11 @@ class DiscordMessage

protected string $url = '';

public function from(string $username, string $avatarUrl = null): self
public function from(?string $username = null, ?string $avatarUrl = null): self
{
$this->username = $username;
if (! is_null($username)) {
$this->username = empty($username) ? 'Laravel Backup' : $username;
}

if (! is_null($avatarUrl)) {
$this->avatarUrl = $avatarUrl;
Expand Down Expand Up @@ -111,7 +113,7 @@ public function fields(array $fields, bool $inline = true): self
public function toArray(): array
{
return [
'username' => $this->username ?? 'Laravel Backup',
'username' => $this->username,
'avatar_url' => $this->avatarUrl,
'embeds' => [
[
Expand Down