public function notify($id) { $post = BlogPost::where('id', '=', $id)->firstOrFail(); if (!$post->notification_sent) { $users = User::where('notify_me', '=', true)->get(); foreach ($users as $user) { $this->mailer->send(['emails.html-notify', 'emails.text-notify'], compact('user', 'post'), function ($message) use($user) { $message->to($user->email)->subject('Un nouvel article est en ligne'); }); } } }
public static function boot() { parent::boot(); // cause a delete of a category to cascade to children so they are also deleted static::deleted(function ($category) { $posts = BlogPost::where('category_id', '=', $category->id)->get(); if (!empty($posts)) { foreach ($posts as $post) { $comments = Comment::where('on_post', '=', $post->id); $comments->delete(); } $category->posts()->delete(); } }); }