本文整理汇总了PHP中app\Post::withTrashed方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::withTrashed方法的具体用法?PHP Post::withTrashed怎么用?PHP Post::withTrashed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::withTrashed方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->timestamp('bumplocked_at')->nullable()->default(null)->after('stickied_at');
$table->timestamp('locked_at')->nullable()->default(null)->after('bumplocked_at');
$table->timestamp('bumped_last')->nullable()->default(null)->after('reply_last');
});
Post::withTrashed()->whereNull('bumped_last')->update(["bumped_last" => DB::raw("reply_last")]);
}
示例2: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->string('author_ip', 46)->nullable()->change();
$table->string('author_id', 6)->nullable()->after('author_ip');
$table->timestamp('author_ip_nulled_at')->nullable()->after('author_id');
});
Post::withTrashed()->chunk(100, function ($posts) {
foreach ($posts as $post) {
$post->author_id = $post->makeAuthorId();
$post->save();
}
});
}
示例3: down
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('bans', function (Blueprint $table) {
$table->string('ban_ip', 46)->after('ban_ip_end');
});
Schema::table('posts', function (Blueprint $table) {
$table->string('author_ip_string', 46)->after('author_ip');
});
Schema::table('reports', function (Blueprint $table) {
$table->string('ip', 46)->after('reporter_ip');
});
Ban::chunk(100, function ($bans) {
foreach ($bans as $ban) {
$ban->ban_ip_start = inet_ntop($ban->ban_ip);
$ban->ban_ip_end = inet_ntop($ban->ban_ip);
$ban->save();
}
});
Post::withTrashed()->chunk(100, function ($posts) {
foreach ($posts as $post) {
$post->author_ip_string = null;
if (!is_null($post->author_ip)) {
$post->author_ip_string = inet_ntop($post->author_ip);
}
$post->save();
}
});
Report::chunk(100, function ($reports) {
foreach ($reports as $report) {
$report->ip = inet_ntop($report->reporter_ip);
$report->save();
}
});
Schema::table('bans', function (Blueprint $table) {
$table->dropColumn('ban_ip_start', 'ban_ip_end');
});
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('author_ip');
});
Schema::table('posts', function (Blueprint $table) {
$table->renameColumn('author_ip_string', 'author_ip');
});
Schema::table('reports', function (Blueprint $table) {
$table->dropColumn('reporter_ip');
});
}
示例4: 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).");
}
}
示例5: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->bigInteger('reply_to_board_id')->unsigned()->nullable()->after('reply_to');
});
// Add reply_to_board_id for all posts.
$replies = Post::withTrashed()->whereNotNull('posts.reply_to')->leftJoin('posts as op', function ($join) {
$join->on('op.post_id', '=', 'posts.reply_to');
})->addSelect('posts.*', 'op.board_id as op_board_id')->get();
foreach ($replies as $reply) {
$reply->reply_to_board_id = $reply->op_board_id;
try {
$reply->save();
} catch (Exception $e) {
dd($e);
}
}
}
示例6: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('post_cites', function (Blueprint $table) {
$table->bigIncrements('post_cite_id');
$table->bigInteger('post_id')->unsigned();
$table->string('post_board_uri', 32);
$table->bigInteger('post_board_id')->unsigned();
$table->bigInteger('cite_id')->unsigned()->nullable();
$table->string('cite_board_uri', 32);
$table->bigInteger('cite_board_id')->unsigned()->nullable();
$table->foreign('post_id')->references('post_id')->on('posts')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('post_board_uri')->references('board_uri')->on('boards')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('cite_id')->references('post_id')->on('posts')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('cite_board_uri')->references('board_uri')->on('boards')->onDelete('cascade')->onUpdate('cascade');
});
// Process citations.
$posts = Post::withTrashed()->chunk(100, function ($posts) {
echo " - Adding citations for 100 posts.\n";
foreach ($posts as $post) {
$cited = $post->getCitesFromText();
$cites = [];
foreach ($cited['posts'] as $citedPost) {
if (is_null($citedPost->deleted_at)) {
$cites[] = new PostCite(['post_board_uri' => $post->board_uri, 'post_board_id' => $post->board_id, 'cite_id' => $citedPost->post_id, 'cite_board_uri' => $citedPost->board_uri, 'cite_board_id' => $citedPost->board_id]);
}
}
foreach ($cited['boards'] as $citedBoard) {
$cites[] = new PostCite(['post_board_uri' => $post->board_uri, 'cite_board_uri' => $citedBoard->board_uri]);
}
if (count($cites) > 0) {
try {
$post->cites()->saveMany($cites);
} catch (Exception $e) {
dd($post);
}
}
}
});
}
示例7: __getPosts
/**
* @return \Illuminate\Contracts\Pagination\Paginator
*/
protected function __getPosts()
{
$posts = Post::withTrashed()->orderBy('date', 'DESC')->simplePaginate(8);
$posts->setPath(route('load_next_posts'));
return $posts;
}
示例8: 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).");
}
}
示例9: restore
public function restore($id)
{
$post = Post::withTrashed()->where('id', '=', $id)->restore();
return ['message' => 'Articolo nuovamente visibile'];
}
示例10: 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);
}
示例11: getRestore
/**
* Restored post from trash
*/
public function getRestore($id)
{
$post = Post::withTrashed()->find($id);
$post->restore();
return redirect('post/deleted-post')->with('restore', true);
}