/** * Manage post personal information (IPs) * * @return void */ protected function handlePostInformation() { $this->comment(" Pruning posts data..."); $postIpLife = (int) Settings::get('ephePostIpLife', 0); $postTrashedLife = (int) Settings::get('ephePostHardDelete', 0); if ($postIpLife) { $carbonLife = Carbon::now()->subDays($postIpLife); $affected = Post::withTrashed()->where('created_at', '<=', $carbonLife)->whereNotNull('author_ip')->update(['author_ip' => null]); $this->comment(" Pruned {$affected} author IP(s)."); } if ($postTrashedLife) { $carbonLife = Carbon::now()->subDays($postTrashedLife); // Destroy old, trashed posts. $affected = Post::onlyTrashed()->where('deleted_at', '<=', $carbonLife)->forceDelete(); $this->comment(" Pruned {$affected} trashed post(s)."); } }
/** * Manage post personal information (IPs) * * @return void */ protected function handlePostInformation() { $this->comment(" Pruning posts data..."); $postIpLife = (int) Settings::get('ephePostIpLife', 0); $postTrashedLife = (int) Settings::get('ephePostHardDelete', 0); if ($postIpLife) { $carbonLife = Carbon::now()->subDays($postIpLife); $affected = Post::withTrashed()->where('created_at', '<=', $carbonLife)->whereNotNull('author_ip')->update(['author_ip' => null]); $this->comment(" Pruned {$affected} author IP(s)."); } if ($postTrashedLife) { $carbonLife = Carbon::now()->subDays($postTrashedLife); // Find old posts. $forTrash = Post::onlyTrashed()->select('post_id', 'deleted_at')->where('deleted_at', '<=', $carbonLife); // Remove relationships. $forTrash->chunk(100, function ($posts) { foreach ($posts as $post) { $post->attachmentLinks()->delete(); } }); // Destroy old, trashed posts. $affected = $forTrash->forceDelete(); $this->comment(" Pruned {$affected} trashed post(s)."); } }
public function testSoftDelete() { // test trashed() $post = Post::find(1); $post->delete(); $this->assertTrue($post->trashed()); // test withTrashed() Post::find(2)->delete(); $post = Post::find(2); $this->assertNull($post); $post = Post::withTrashed()->find(2); $this->assertNotNull($post); // test onlyTrashed() $post = Post::find(3); $this->assertNotNull($post); $post = Post::onlyTrashed()->find(3); $this->assertNull($post); // test restore $post = Post::find(3); $post->delete(); $post->restore(); $post1 = Post::find(3); $this->assertNull($post1); $post = Post::onlyTrashed()->find(3); $post->restore(); $post1 = Post::find(3); $this->assertNotNull($post1); }
public function archive() { return Post::onlyTrashed()->get(); }
/** * Display a listing of deleted post */ public function getDeletedPost() { $post = Post::onlyTrashed()->get(); return view('admin/post/deletedPost', array('user' => $this->username, 'nav_post' => '', 'nav_del_post' => '', 'posts' => $post)); }