<?php 

namespace App\Observers;

use Auth;
use App\Models\UserLog;

class ModelObserver {

    private $user_id;
    private $model;

    public function __construct(){
        $this->user_id = Auth::id();
    }

    public function created($model)
    {
        UserLog::create([
            'model_name' => get_class($model),
            'model_id' => $model->id,
            'log_name' => 'create',
            'user_id' => $this->user_id,
        ]);
    }

    public function updated($model)
    {
        UserLog::create([
            'model_name' => get_class($model),
            'model_id' => $model->id,
            'log_name' => 'update',
            'user_id' => $this->user_id,
        ]);
    }

    public function deleted($model)
    {
        UserLog::create([
            'model_name' => get_class($model),
            'model_id' => $model->id,
            'log_name' => 'delete',
            'user_id' => $this->user_id,
        ]);
    }

}