2019-09-17 23:10:44 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\View\Composers;
|
|
|
|
|
2020-05-31 16:20:34 +08:00
|
|
|
use App\Models\User;
|
2019-12-29 11:49:31 +08:00
|
|
|
use Blessing\Filter;
|
2019-09-17 23:10:44 +08:00
|
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
2019-12-14 11:10:37 +08:00
|
|
|
use Illuminate\View\View;
|
2019-09-17 23:10:44 +08:00
|
|
|
|
|
|
|
class UserPanelComposer
|
|
|
|
{
|
|
|
|
/** @var Dispatcher */
|
|
|
|
protected $dispatcher;
|
|
|
|
|
2019-12-22 17:22:05 +08:00
|
|
|
/** @var Filter */
|
|
|
|
protected $filter;
|
|
|
|
|
|
|
|
public function __construct(Dispatcher $dispatcher, Filter $filter)
|
2019-09-17 23:10:44 +08:00
|
|
|
{
|
|
|
|
$this->dispatcher = $dispatcher;
|
2019-12-22 17:22:05 +08:00
|
|
|
$this->filter = $filter;
|
2019-09-17 23:10:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function compose(View $view)
|
|
|
|
{
|
2020-05-31 16:20:34 +08:00
|
|
|
/** @var User */
|
2019-09-17 23:10:44 +08:00
|
|
|
$user = auth()->user();
|
2020-01-13 08:37:57 +08:00
|
|
|
$avatarUrl = route('avatar.user', ['uid' => $user->uid, 'size' => 45]);
|
2019-12-23 10:03:08 +08:00
|
|
|
$avatar = $this->filter->apply('user_avatar', $avatarUrl, [$user]);
|
2019-09-17 23:10:44 +08:00
|
|
|
|
|
|
|
$badges = [];
|
2020-05-31 16:20:34 +08:00
|
|
|
if ($user->isAdmin()) {
|
2019-12-11 23:29:20 +08:00
|
|
|
$badges[] = ['text' => 'STAFF', 'color' => 'primary'];
|
|
|
|
}
|
2019-09-17 23:10:44 +08:00
|
|
|
$this->dispatcher->dispatch(new \App\Events\RenderingBadges($badges));
|
2020-05-31 16:20:34 +08:00
|
|
|
$badges = $this->filter->apply('user_badges', $badges, [$user]);
|
2019-09-17 23:10:44 +08:00
|
|
|
|
2019-12-22 17:22:05 +08:00
|
|
|
$view->with(compact('user', 'avatar', 'badges'));
|
2019-09-17 23:10:44 +08:00
|
|
|
}
|
|
|
|
}
|