clrghouz/app/Http/Middleware/AddUserToView.php

50 lines
996 B
PHP
Raw Normal View History

2021-09-27 14:21:21 +00:00
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\Auth\Authenticatable;
class AddUserToView
{
2023-06-27 07:39:11 +00:00
/**
* The View Factory.
*
* @var \Illuminate\Contracts\View\Factory
*/
protected Factory $factory;
2021-09-27 14:21:21 +00:00
2023-06-27 07:39:11 +00:00
/**
* The Authenticated user, if any.
*
* @var \Illuminate\Contracts\Auth\Authenticatable|null
*/
protected ?Authenticatable $user;
2021-09-27 14:21:21 +00:00
2023-06-27 07:39:11 +00:00
/**
* Create a new Share Authenticated User instance.
*
* @param \Illuminate\Contracts\View\Factory $factory
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
*/
public function __construct(Factory $factory,Authenticatable $user=NULL)
{
$this->factory = $factory;
$this->user = $user;
}
2021-09-27 14:21:21 +00:00
2023-06-27 07:39:11 +00:00
/**
* 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);
2021-09-27 14:21:21 +00:00
2023-06-27 07:39:11 +00:00
return $next($request);
}
2021-09-27 14:21:21 +00:00
}