<?php
namespace App\Http\View\Composers;

use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;

class LogComposer {

    /**
     * Bind data to the view.
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {

        if(auth()->user()){
            $url = url()->current();
            $ip = \request()->ip();

            // log to all page
            $auth = auth()->id();
            $username = auth()->user()->username ?? '';
            $company_name = auth()->user()->organisation ?? '';

            Log::channel('deywuro_user')->info("[user_id:$auth] [username:$username] [company_name:$company_name] [current_url:$url] [ip:$ip]");


        }else{
            $url = url()->current();
            $ip = \request()->ip();

            Log::channel('pre_login')->info("[current_url:$url] [ip:$ip]");

        }
    }

}
