Skip to content

Commit

Permalink
Merge pull request #160 from kellerjmrtn/add-support-for-blade-views
Browse files Browse the repository at this point in the history
Add view() Method Which Renders HTML Via A Blade View
  • Loading branch information
realrashid authored Mar 2, 2024
2 parents b641499 + a59cc4a commit 2d38720
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Toaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RealRashid\SweetAlert;

use Illuminate\Contracts\View\Factory as ViewFactory;
use RealRashid\SweetAlert\Storage\SessionStore;

class Toaster
Expand All @@ -14,6 +15,14 @@ class Toaster
*/
protected $session;

/**
* View Factory.
*
* @var \Illuminate\Contracts\View\Factory
* @author Keller Martin <[email protected]>
*/
protected ViewFactory $view;

/**
* Configuration options.
*
Expand All @@ -26,12 +35,14 @@ class Toaster
* Setting up the session
*
* @param SessionStore $session
* @param ViewFactory $view
* @author Rashid Ali <[email protected]>
*/
public function __construct(SessionStore $session)
public function __construct(SessionStore $session, ViewFactory $view)
{
$this->setDefaultConfig();
$this->session = $session;
$this->view = $view;
}

/**
Expand Down Expand Up @@ -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 <[email protected]>
*/
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
*
Expand Down

0 comments on commit 2d38720

Please sign in to comment.