|  | @@ -0,0 +1,36 @@
 | 
	
		
			
			|  | 1 | +<?php
 | 
	
		
			
			|  | 2 | +
 | 
	
		
			
			|  | 3 | +namespace App\Http\ViewComposers;
 | 
	
		
			
			|  | 4 | +
 | 
	
		
			
			|  | 5 | +use Auth;
 | 
	
		
			
			|  | 6 | +use App\Models\FunMenu;
 | 
	
		
			
			|  | 7 | +use Illuminate\View\View;
 | 
	
		
			
			|  | 8 | +
 | 
	
		
			
			|  | 9 | +class LeftMenuComposer
 | 
	
		
			
			|  | 10 | +{
 | 
	
		
			
			|  | 11 | +
 | 
	
		
			
			|  | 12 | +    protected $user_id;
 | 
	
		
			
			|  | 13 | +    protected $user_name;
 | 
	
		
			
			|  | 14 | +
 | 
	
		
			
			|  | 15 | +    public function __construct()
 | 
	
		
			
			|  | 16 | +    {
 | 
	
		
			
			|  | 17 | +        if (Auth::check()) {
 | 
	
		
			
			|  | 18 | +            // 這個使用者已經登入...
 | 
	
		
			
			|  | 19 | +            $user = Auth::user();
 | 
	
		
			
			|  | 20 | +
 | 
	
		
			
			|  | 21 | +            $this->user_id = $user->id;
 | 
	
		
			
			|  | 22 | +            $this->user_name = $user->name;
 | 
	
		
			
			|  | 23 | +        } else {
 | 
	
		
			
			|  | 24 | +            $this->user_id = 0;
 | 
	
		
			
			|  | 25 | +            $this->user_name = "Guest";
 | 
	
		
			
			|  | 26 | +        }
 | 
	
		
			
			|  | 27 | +    }
 | 
	
		
			
			|  | 28 | +
 | 
	
		
			
			|  | 29 | +    public function compose(View $view)
 | 
	
		
			
			|  | 30 | +    {
 | 
	
		
			
			|  | 31 | +        $view->with([
 | 
	
		
			
			|  | 32 | +            'leftmenu' => (new FunMenu)->leftmenu($this->user_id),
 | 
	
		
			
			|  | 33 | +            'username' => $this->user_name
 | 
	
		
			
			|  | 34 | +        ]);
 | 
	
		
			
			|  | 35 | +    }
 | 
	
		
			
			|  | 36 | +}
 |