diff --git a/src/Toaster.php b/src/Toaster.php index d965817..9e8cb10 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; } /** @@ -274,6 +285,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 *