59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Inertia\Inertia;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Inertia\ResponseFactory;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
public const HOME = '/';
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
ResponseFactory::macro('client', function ($component, $props = []) {
|
|
return Inertia::render($component, $props)->rootView('client');
|
|
});
|
|
ResponseFactory::macro('admin', function ($component, $props = []) {
|
|
return Inertia::render($component, $props)->rootView('app');
|
|
});
|
|
|
|
|
|
|
|
Inertia::share([
|
|
'errors' => function () {
|
|
return Session::get('errors')
|
|
? Session::get('errors')->getBag('default')->getMessages()
|
|
: (object) [];
|
|
},
|
|
'auth' => function () {
|
|
$user = Auth::user();
|
|
$permissions = $user ? $user->getAllPermissions()->pluck('name') : [];
|
|
return [
|
|
'User' => $user,
|
|
'permissions' => $permissions,
|
|
];
|
|
},
|
|
]);
|
|
Inertia::share('flash', function () {
|
|
return [
|
|
'success' => Session::get('success'),
|
|
'error' => Session::get('error'),
|
|
];
|
|
});
|
|
}
|
|
}
|