<?php

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

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

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

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

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

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

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

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

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