<?php

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

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

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

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

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

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

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

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

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