Thanks to visit codestin.com
Credit goes to github.com

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
94 changes: 94 additions & 0 deletions src/Alert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Native\Laravel;

use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use Native\Laravel\Client\Client;
use Native\Laravel\Facades\Window;

class Alert
{
protected ?string $type;
protected ?string $title;
protected ?string $detail;
protected ?array $buttons;
protected ?int $defaultId;
protected ?int $cancelId;

final public function __construct(protected Client $client)
{
}

public static function new()
{
return new static(new Client);
}

public function type(string $type): self
{
$this->type = $type;

return $this;
}

public function title(string $title): self
{
$this->title = $title;

return $this;
}

public function detail(string $detail): self
{
$this->detail = $detail;

return $this;
}

public function buttons(array $buttons): self
{
$this->buttons = $buttons;

return $this;
}

public function defaultId(int $defaultId): self
{
$this->defaultId = $defaultId;

return $this;
}

public function cancelId(int $cancelId): self
{
$this->cancelId = $cancelId;

return $this;
}

public function show(string $message): int
{
$response = $this->client->post('alert/message', [
'message' => $message,
'type' => $this->type,
'title' => $this->title,
'detail' => $this->detail,
'buttons' => $this->buttons,
'defaultId' => $this->defaultId,
'cancelId' => $this->cancelId
]);

return (int) $response->json('result');
}

public function error(string $title, string $message): bool
{
$response = $this->client->post('alert/error', [
'title' => $title,
'message' => $message,
]);

return (bool) $response->json('result');
}
}
23 changes: 23 additions & 0 deletions src/Facades/Alert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Native\Laravel\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static static type(string $type)
* @method static static title(string $title)
* @method static static detail(string $detail)
* @method static static buttons(string[] $buttons)
* @method static static defaultId(int $defaultId)
* @method static static cancelId(int $cancelId)
* @method static int show(string $message)
* @method static bool error(string $title, string $message)
*/
class Alert extends Facade
{
protected static function getFacadeAccessor()
{
return \Native\Laravel\Alert::class;
}
}
Loading