Last active
September 7, 2020 09:31
-
-
Save lagbox/0913f51f534ff9fe9941577ff5848eda to your computer and use it in GitHub Desktop.
ShareLater functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
public function boot() | |
{ | |
View::shareLater('user', function () { | |
return auth()->user(); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\View\ShareLater; | |
// | |
/** | |
* Share a callback to be resolved later. | |
* | |
* @param string $key | |
* @param callable|string $callback | |
* @param boolean $once | |
* @return void | |
*/ | |
public function shareLater($key, $callback, $once = true) | |
{ | |
$this->share($key, new ShareLater($this->container, $callback, $once)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Contracts\View\Shareable; | |
// | |
public function gatherData() | |
{ | |
$data = array_merge($this->factory->getShared(), $this->data); | |
foreach ($data as $key => $value) { | |
if ($value instanceof Renderable) { | |
$data[$key] = $value->render(); | |
} elseif ($value instanceof Shareable) { | |
$data[$key] = $value->share(); | |
} | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment