<?php

namespace App\Observers;
use Illuminate\Support\Facades\Auth;
use App\Subject;
use Illuminate\Database\Eloquent\SoftDeletes;

class SubjectObserver
{
    use SoftDeletes;
    /**
     * Handle the subject "created" event.
     *
     * @param  \App\Subject  $subject
     * @return void
     */
    public function created(Subject $subject)
    {
        //
    }

    /**
     * Handle the subject "updated" event.
     *
     * @param  \App\Subject  $subject
     * @return void
     */
    public function updated(Subject $subject)
    {
        //
    }

    /**
     * Handle the subject "deleted" event.
     *
     * @param  \App\Subject  $subject
     * @return void
     */
    public function deleted(Subject $subject)
    {
        $id = Auth::id();
        error_log("Deleted".$id);
       
        $subject->deleted_by=$id;   
    }

    /**
     * Handle the subject "restored" event.
     *
     * @param  \App\Subject  $subject
     * @return void
     */
    public function restored(Subject $subject)
    {
        //
    }

    /**
     * Handle the subject "force deleted" event.
     *
     * @param  \App\Subject  $subject
     * @return void
     */
    public function forceDeleted(Subject $subject)
    {
        //
    }

    /**
     * Handle the Subject "creating" event.
     *
     * @param  \App\Subject  $Subject
     * @return void
     */
    public function creating(Subject $subject)
    {
      
        $id = Auth::id();
        $subject->created_by=$id;
        $subject->updated_by=$id;   
    }

    /**
     * Handle the Subject "updating" event.
     *
     * @param  \App\Subject  $Subject
     * @return void
     */
    public function updating(Subject $subject)
    {
      
        $id = Auth::id();
        $subject->updated_by=$id;   
    }

    /**
     * Handle the Subject "deleting" event.
     *
     * @param  \App\Subject  $Subject
     * @return void
     */
    public function deleting(Subject $subject)
    {
        $id = Auth::id();
        error_log("Deleting".$id);
       
        $subject->deleted_by=$id;   
    }
}
