From 2c406ba3e9edf04e8cea79b0eff8af6e6ea697db Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 28 Sep 2021 00:21:21 +1000 Subject: [PATCH] Add $user (authed user) to views --- app/Http/Kernel.php | 1 + app/Http/Middleware/AddUserToView.php | 50 +++++++++++++++++++ resources/views/domain/view.blade.php | 2 +- .../views/layouts/partials/sidebar.blade.php | 2 +- .../views/layouts/partials/topmenu.blade.php | 4 +- resources/views/user/addedit.blade.php | 6 +-- resources/views/user/home.blade.php | 2 +- 7 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 app/Http/Middleware/AddUserToView.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 1b44804..3a7f63a 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -36,6 +36,7 @@ class Kernel extends HttpKernel \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class, + \App\Http\Middleware\AddUserToView::class, ], 'api' => [ diff --git a/app/Http/Middleware/AddUserToView.php b/app/Http/Middleware/AddUserToView.php new file mode 100644 index 0000000..6df4069 --- /dev/null +++ b/app/Http/Middleware/AddUserToView.php @@ -0,0 +1,50 @@ +factory = $factory; + $this->user = $user; + } + + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + $this->factory->share('user',$this->user); + + return $next($request); + } +} \ No newline at end of file diff --git a/resources/views/domain/view.blade.php b/resources/views/domain/view.blade.php index f55133f..edfe09b 100644 --- a/resources/views/domain/view.blade.php +++ b/resources/views/domain/view.blade.php @@ -150,7 +150,7 @@ @guest To start an application to join this network please login. @else - @if(Auth::user()->isMember($o)) + @if($user->isMember($o)) @else This website is not ready to take applications yet, check back soon! @endif diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index b4a83c5..c330db6 100644 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -27,7 +27,7 @@
Expore Networks
@foreach (\App\Models\Domain::active() - ->when(! \Illuminate\Support\Facades\Auth::check(),function($query) { return $query->public(); }) + ->when((! $user),function($query) { return $query->public(); }) ->orderBy('name')->get() as $o)
{{ $o->name }}
@endforeach diff --git a/resources/views/layouts/partials/topmenu.blade.php b/resources/views/layouts/partials/topmenu.blade.php index dfeb503..c381a00 100644 --- a/resources/views/layouts/partials/topmenu.blade.php +++ b/resources/views/layouts/partials/topmenu.blade.php @@ -15,8 +15,8 @@