From a59cc4abee34fe821a6b5c66d9b7d4eff36fe621 Mon Sep 17 00:00:00 2001 From: Keller Martin Date: Tue, 27 Jun 2023 18:10:52 -0400 Subject: [PATCH] Add view() Method Which Renders HTML Via A Blade View --- src/Toaster.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Toaster.php b/src/Toaster.php index 37c4945..2f95495 100644 --- a/src/Toaster.php +++ b/src/Toaster.php @@ -2,6 +2,7 @@ namespace RealRashid\SweetAlert; +use Illuminate\Contracts\View\Factory as ViewFactory; use RealRashid\SweetAlert\Storage\SessionStore; class Toaster @@ -14,6 +15,14 @@ class Toaster */ protected $session; + /** + * View Factory. + * + * @var \Illuminate\Contracts\View\Factory + * @author Keller Martin + */ + protected ViewFactory $view; + /** * Configuration options. * @@ -26,12 +35,14 @@ class Toaster * Setting up the session * * @param SessionStore $session + * @param ViewFactory $view * @author Rashid Ali */ - public function __construct(SessionStore $session) + public function __construct(SessionStore $session, ViewFactory $view) { $this->setDefaultConfig(); $this->session = $session; + $this->view = $view; } /** @@ -268,6 +279,23 @@ public function html($title = '', $code = '', $icon = '') return $this; } + /** + * Display an html typed alert message which is generated from a view + * + * @param string $title + * @param string $view + * @param array $data + * @param array $mergeData + * @param string $icon + * @author Keller Martin + */ + public function view($title, $view, $data = [], $mergeData = [], $icon = '') + { + $html = $this->view->make($view, $data, $mergeData)->render(); + + return $this->html($title, $html, $icon); + } + /** * Display a toast message *