86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Traits;
|
||
|
|
|
||
|
|
use Illuminate\Support\Facades\Blade;
|
||
|
|
|
||
|
|
trait Toast
|
||
|
|
{
|
||
|
|
public function toast(
|
||
|
|
string $type,
|
||
|
|
string $title,
|
||
|
|
?string $description = null,
|
||
|
|
?string $position = null,
|
||
|
|
string $icon = 'o-information-circle',
|
||
|
|
string $css = 'alert-info',
|
||
|
|
int $timeout = 3000,
|
||
|
|
?string $redirectTo = null
|
||
|
|
) {
|
||
|
|
$toast = [
|
||
|
|
'type' => $type,
|
||
|
|
'title' => $title,
|
||
|
|
'description' => $description,
|
||
|
|
'position' => $position,
|
||
|
|
'icon' => Blade::render("<x-ui.icon class='w-7 h-7' name='".$icon."' />"),
|
||
|
|
'css' => $css,
|
||
|
|
'timeout' => $timeout,
|
||
|
|
];
|
||
|
|
|
||
|
|
$this->js('toast('.json_encode(['toast' => $toast]).')');
|
||
|
|
|
||
|
|
if ($redirectTo) {
|
||
|
|
return $this->redirect($redirectTo, navigate: true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function success(
|
||
|
|
string $title,
|
||
|
|
?string $description = null,
|
||
|
|
?string $position = null,
|
||
|
|
string $icon = 'o-check-circle',
|
||
|
|
string $css = 'alert-success',
|
||
|
|
int $timeout = 3000,
|
||
|
|
?string $redirectTo = null
|
||
|
|
) {
|
||
|
|
return $this->toast('success', $title, $description, $position, $icon, $css, $timeout, $redirectTo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function warning(
|
||
|
|
string $title,
|
||
|
|
?string $description = null,
|
||
|
|
?string $position = null,
|
||
|
|
string $icon = 'o-exclamation-triangle',
|
||
|
|
string $css = 'alert-warning',
|
||
|
|
int $timeout = 3000,
|
||
|
|
?string $redirectTo = null
|
||
|
|
) {
|
||
|
|
return $this->toast('warning', $title, $description, $position, $icon, $css, $timeout, $redirectTo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function error(
|
||
|
|
string $title,
|
||
|
|
?string $description = null,
|
||
|
|
?string $position = null,
|
||
|
|
string $icon = 'o-x-circle',
|
||
|
|
string $css = 'alert-error',
|
||
|
|
int $timeout = 3000,
|
||
|
|
?string $redirectTo = null
|
||
|
|
) {
|
||
|
|
return $this->toast('error', $title, $description, $position, $icon, $css, $timeout, $redirectTo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function info(
|
||
|
|
string $title,
|
||
|
|
?string $description = null,
|
||
|
|
?string $position = null,
|
||
|
|
string $icon = 'o-information-circle',
|
||
|
|
string $css = 'alert-info',
|
||
|
|
int $timeout = 3000,
|
||
|
|
?string $redirectTo = null
|
||
|
|
) {
|
||
|
|
return $this->toast('info', $title, $description, $position, $icon, $css, $timeout, $redirectTo);
|
||
|
|
}
|
||
|
|
}
|