Skip to content

Instantly share code, notes, and snippets.

@ChadTaljaardt
Created April 26, 2016 23:27
Show Gist options
  • Save ChadTaljaardt/bf77bd438ba58d836253668592d26836 to your computer and use it in GitHub Desktop.
Save ChadTaljaardt/bf77bd438ba58d836253668592d26836 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\ViewComposers;
use Illuminate\View\View;
use App\Models\Store\Cart as Cart;
use Auth;
use App\Categories as Categories;
class HeaderComposer
{
protected $cartCount;
public function __construct()
{
if(Auth::user())
{
$cart = Cart::current();
$this->cartCount = $cart->items()->count();
} else {
$this->cartCount = 0;
}
}
public function compose(View $view)
{
$categories = Categories::where('enabled', '1')->get();
$view->with(['count' => $this->cartCount, 'categories' => $categories]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment