Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Created January 11, 2020 20:53
Show Gist options
  • Save DarkGhostHunter/29628543c4c62a6603a7a28cd48dc3e5 to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/29628543c4c62a6603a7a28cd48dc3e5 to your computer and use it in GitHub Desktop.
Adds the authenticated user globally to all views
<?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