blessing-skin-server/app/Http/View/Composers/UserPanelComposer.php
2019-12-29 11:49:31 +08:00

38 lines
923 B
PHP

<?php
namespace App\Http\View\Composers;
use Blessing\Filter;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\View\View;
class UserPanelComposer
{
/** @var Dispatcher */
protected $dispatcher;
/** @var Filter */
protected $filter;
public function __construct(Dispatcher $dispatcher, Filter $filter)
{
$this->dispatcher = $dispatcher;
$this->filter = $filter;
}
public function compose(View $view)
{
$user = auth()->user();
$avatarUrl = url('/avatar/user/'.$user->uid.'/45');
$avatar = $this->filter->apply('user_avatar', $avatarUrl, [$user]);
$badges = [];
if (auth()->user()->isAdmin()) {
$badges[] = ['text' => 'STAFF', 'color' => 'primary'];
}
$this->dispatcher->dispatch(new \App\Events\RenderingBadges($badges));
$view->with(compact('user', 'avatar', 'badges'));
}
}