Created
January 11, 2020 20:53
-
-
Save DarkGhostHunter/29628543c4c62a6603a7a28cd48dc3e5 to your computer and use it in GitHub Desktop.
Adds the authenticated user globally to all views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\View\Composers; | |
use Illuminate\Contracts\Auth\Authenticatable; | |
use Illuminate\View\View; | |
class AuthenticatedComposer | |
{ | |
/** | |
* The authenticated Client | |
* | |
* @var \App\User | |
*/ | |
protected $user; | |
/** | |
* Create a new authenticated composer. | |
* | |
* @param null|\Illuminate\Contracts\Auth\Authenticatable $user | |
*/ | |
public function __construct(Authenticatable $user = null) | |
{ | |
$this->user = $user; | |
} | |
/** | |
* Bind data to the view. | |
* | |
* @param \Illuminate\View\View $view | |
* @return void | |
*/ | |
public function compose(View $view) | |
{ | |
$view->with('authenticated', $this->user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment