Last active
May 20, 2019 17:49
-
-
Save amir9480/71bd3e4f48a403eb2abe4f9605326a09 to your computer and use it in GitHub Desktop.
vasiat laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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