This commit is contained in:
2024-09-01 18:54:23 +05:00
parent 76d18365a5
commit 061f09eca1
1597 changed files with 109451 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace Laravel\Nova\Notifications;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Notification extends Model
{
use SoftDeletes;
protected $table = 'nova_notifications';
protected $guarded = [];
public $incrementing = false;
public $casts = [
'data' => 'array',
'read_at' => 'datetime',
];
/**
* Return the notifiable relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function notifiable()
{
return $this->morphTo();
}
/**
* Scope the given query by unread notifications.
*
* @return void
*/
public static function scopeUnread(Builder $query)
{
$query->whereNull('read_at');
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Laravel\Nova\Notifications;
use Illuminate\Notifications\Notification as LaravelNotification;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
class NovaChannel
{
/**
* Send channel notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, LaravelNotification $notification)
{
if (app()->environment('local') ||
Gate::forUser($notifiable)->check('viewNova')) {
Notification::create([
'id' => Str::orderedUuid(),
'type' => get_class($notification),
'notifiable_id' => $notifiable->getKey(),
'notifiable_type' => $notifiable->getMorphClass(),
'data' => $notification->toNova($notifiable),
]);
}
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace Laravel\Nova\Notifications;
use Laravel\Nova\Exceptions\HelperNotSupported;
use Laravel\Nova\Makeable;
use Laravel\Nova\Nova;
use Laravel\Nova\URL;
class NovaNotification extends \Illuminate\Notifications\Notification
{
use Makeable;
const SUCCESS_TYPE = 'success';
const ERROR_TYPE = 'error';
const WARNING_TYPE = 'warning';
const INFO_TYPE = 'info';
/**
* The notification available types text CSS.
*
* @var array
*/
public static $types = [
self::SUCCESS_TYPE => 'text-green-500',
self::ERROR_TYPE => 'text-red-500',
self::WARNING_TYPE => 'text-yellow-500',
self::INFO_TYPE => 'text-sky-500',
];
/**
* The component used for the notification.
*
* @var string
*/
public $component = 'message-notification';
/**
* The icons used for the notification.
*
* @var string
*/
public $icon = 'exclamation-circle';
/**
* The message used for the notification.
*
* @var string|null
*/
public $message;
/**
* The text used for the call-to-action button label.
*
* @var string
*/
public $actionText = 'View';
/**
* The URL used for the call-to-action button.
*
* @var \Laravel\Nova\URL|string|null
*/
public $actionUrl;
/**
* Determine if URL should be open in new tab.
*
* @var bool
*/
public $openInNewTab = false;
/**
* The notification's visual type.
*
* @var string
*/
public $type = 'success';
/**
* Set the icon used for the notification.
*
* @param string $icon
* @return $this
*/
public function icon($icon)
{
$this->icon = $icon;
return $this;
}
/**
* Set the message used for the notification.
*
* @param string $message
* @return $this
*/
public function message($message)
{
$this->message = $message;
return $this;
}
/**
* Set the URL used for the notification call-to-action button.
*
* @param string $url
* @return $this
*/
public function url($url)
{
$this->actionUrl = $url;
return $this;
}
/**
* Set the action text and URL used for the notification.
*
* @param string $text
* @param \Laravel\Nova\URL|string $url
* @return $this
*/
public function action(string $text, $url)
{
$this->actionText = $text;
$this->actionUrl = $url;
return $this;
}
/**
* Set URL to open in new tab.
*
* @return $this
*/
public function openInNewTab()
{
if ($this->actionUrl instanceof URL && $this->actionUrl->remote === true) {
$this->openInNewTab = true;
} else {
throw new HelperNotSupported(sprintf('The %s helper method is only applicable on remote URL.', __METHOD__));
}
return $this;
}
/**
* Set the notification's visual type.
*
* @param string $type
* @return $this
*/
public function type(string $type = 'success')
{
$this->type = $type;
return $this;
}
/**
* Get the instance as an array.
*
* @return array
*/
public function toNova()
{
return [
'component' => $this->component,
'icon' => $this->icon,
'message' => $this->message,
'actionText' => Nova::__($this->actionText),
'actionUrl' => $this->actionUrl,
'openInNewTab' => $this->openInNewTab,
'type' => $this->type,
'iconClass' => static::$types[$this->type],
];
}
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return [NovaChannel::class];
}
}