Skip to content

Instantly share code, notes, and snippets.

@amir9480
Last active May 20, 2019 17:49
Show Gist options
  • Save amir9480/71bd3e4f48a403eb2abe4f9605326a09 to your computer and use it in GitHub Desktop.
Save amir9480/71bd3e4f48a403eb2abe4f9605326a09 to your computer and use it in GitHub Desktop.
vasiat laravel
<?php
namespace App\Observers;
use App\BlogComment;
use Illuminate\Support\Facades\Auth;
class BlogCommentObserver
{
/**
* Handle the blog comment "creating" event.
*
* @param \App\BlogComment $blogComment
* @return void
*/
public function creating(BlogComment $blogComment)
{
if (empty($blogComment->ip)) { // فقط وقتی آی پی رو تنظیم میکنم که از قبل تنظیم نشده باشه
$blogComment->ip = request()->ip();
}
}
/**
* Handle the blog comment "deleting" event.
*
* @param \App\BlogComment $blogComment
* @return void
*/
public function deleting(BlogComment $blogComment)
{
foreach ($blogComment->replies()->get() as $reply) {
$reply->delete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment