本文整理汇总了PHP中app\Post::onlyTrashed方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::onlyTrashed方法的具体用法?PHP Post::onlyTrashed怎么用?PHP Post::onlyTrashed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::onlyTrashed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handlePostInformation
/**
* 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).");
}
}
示例2: handlePostInformation
/**
* 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).");
}
}
示例3: testSoftDelete
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);
}
示例4: archive
public function archive()
{
return Post::onlyTrashed()->get();
}
示例5: getDeletedPost
/**
* 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));
}