blessing-skin-server/app/Providers/ViewServiceProvider.php

84 lines
2.8 KiB
PHP
Raw Normal View History

2019-09-17 23:10:44 +08:00
<?php
namespace App\Providers;
use App\Http\View\Composers;
2019-12-14 11:10:37 +08:00
use App\Services\Webpack;
2019-09-17 23:10:44 +08:00
use Illuminate\Support\ServiceProvider;
2020-04-01 16:31:34 +08:00
use Illuminate\Support\Str;
2019-12-14 11:10:37 +08:00
use View;
2019-09-17 23:10:44 +08:00
class ViewServiceProvider extends ServiceProvider
{
2019-09-19 22:13:25 +08:00
public function boot(Webpack $webpack)
2019-09-17 23:10:44 +08:00
{
2019-12-07 16:39:04 +08:00
View::composer([
'home',
'*.base',
'*.master',
2019-12-14 11:10:37 +08:00
'shared.header',
2019-12-07 16:39:04 +08:00
], function ($view) {
2019-12-04 16:45:09 +08:00
$lightColors = ['light', 'warning', 'white', 'orange'];
$color = option('navbar_color');
2019-09-17 23:10:44 +08:00
$view->with([
'site_name' => option_localized('site_name'),
2019-12-04 16:45:09 +08:00
'navbar_color' => $color,
'color_mode' => in_array($color, $lightColors) ? 'light' : 'dark',
2019-12-31 10:00:27 +08:00
'locale' => str_replace('_', '-', app()->getLocale()),
2019-09-17 23:10:44 +08:00
]);
});
View::composer('shared.head', Composers\HeadComposer::class);
View::composer('shared.notifications', function ($view) {
2020-02-08 18:22:52 +08:00
$notifications = auth()->user()->unreadNotifications->map(function ($notification) {
return [
'id' => $notification->id,
'title' => $notification->data['title'],
];
});
$view->with(['notifications' => $notifications]);
2019-09-17 23:10:44 +08:00
});
2020-02-01 12:44:39 +08:00
View::composer(
['shared.languages', 'errors.*'],
Composers\LanguagesMenuComposer::class
);
2019-09-17 23:10:44 +08:00
View::composer('shared.user-menu', Composers\UserMenuComposer::class);
2019-12-04 16:45:09 +08:00
View::composer('shared.sidebar', function ($view) {
$view->with('sidebar_color', option('sidebar_color'));
});
2019-09-17 23:10:44 +08:00
View::composer('shared.side-menu', Composers\SideMenuComposer::class);
View::composer('shared.user-panel', Composers\UserPanelComposer::class);
2019-09-18 23:06:48 +08:00
View::composer('shared.copyright', function ($view) {
2019-09-17 23:10:44 +08:00
$view->with([
'copyright' => option_localized('copyright_prefer', 0),
'custom_copyright' => option_localized('copyright_text'),
'site_name' => option_localized('site_name'),
'site_url' => option('site_url'),
2019-09-17 23:10:44 +08:00
]);
});
View::composer('shared.foot', Composers\FootComposer::class);
2019-09-18 23:06:48 +08:00
2019-09-19 22:13:25 +08:00
View::composer(['errors.*', 'setup.*'], function ($view) use ($webpack) {
2020-04-01 16:31:34 +08:00
// @codeCoverageIgnoreStart
if (Str::startsWith(config('app.asset.env'), 'dev')) {
$view->with(['scripts' => [$webpack->url('spectre.js')]]);
} else {
$view->with('styles', [$webpack->url('spectre.css')]);
}
// @codeCoverageIgnoreEnd
2019-09-19 22:13:25 +08:00
});
2019-12-15 11:19:10 +08:00
View::composer('auth.oauth', function ($view) {
$view->with('providers', resolve('oauth.providers'));
});
2019-09-17 23:10:44 +08:00
}
}