\Illuminate\Database\Eloquent\SoftDeletingScope;
$query->withoutGlobalScope(SoftDeletingScope::class)
->where($article->getDeletedAtColumn(), "<>", null);
<?php
namespace CmsV2\Services\Articles;
use CmsV2\Models\Article;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Database\Query\Builder;
class ArticleTrashListService extends ArticlesListService
{
/**
* 添加过滤条件
* @return \Illuminate\Database\Eloquent\Builder
* @throws \Exception
*/
public function query() {
/** @var $query Builder */
$query = parent::query();
$article = new Article();
$query->withoutGlobalScope(SoftDeletingScope::class)
->where($article->getDeletedAtColumn(), "<>", null);
return $query;
}
}
laravel database migration
php artisan make:migration create_article_read_table
先生成迁移文件./database/migrations/2021_06_17_093830_create_article_read_table.php
补充up方法
Schema::create('life_cms_article_read', function (Blueprint $table) {
$table->increments('id');
$table->integer('content_id')->comment('文章id');
$table->integer('user_id')->comment('用户id');
$table->tinyInteger('type')->comment('1.会员用户 2商户用户');
$table->tinyInteger('read_status')->default(0)->comment('状态 1 已读 0 未读 -1 删除');
$table->timestamps();
});
生成表:
php artisan migrate --path=./database/migrations/2021_06_17_093830_create_article_read_table.php
修改字段后更新表结构
php artisan migrate --path=./database/migrations/2021_08_17_095756_xx_log.php
回滚
php artisan migrate:rollback --step=1