FEATURE: add soft deletes to content pages
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
@@ -15,6 +16,7 @@ use Modules\Categories\Entities\Category;
|
||||
*/
|
||||
class Content extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
public $timestamps = true;
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
@@ -38,7 +40,6 @@ class Content extends Model
|
||||
protected $guarded = [];
|
||||
protected $subpages = [];
|
||||
protected $subpagesInit = false;
|
||||
const STATUS_DELETED = 'deleted';
|
||||
const STATUS_DRAFT = 'draft';
|
||||
const STATUS_PROTECTED = 'protected';
|
||||
const STATUS_PUBLIC = 'public';
|
||||
@@ -59,8 +60,7 @@ class Content extends Model
|
||||
*/
|
||||
public function getPageQuery()
|
||||
{
|
||||
return Content::where('status', '!=', Content::STATUS_DELETED)
|
||||
->where('status', '!=', Content::STATUS_DRAFT);
|
||||
return Content::where('status', '!=', Content::STATUS_DRAFT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,6 +179,7 @@ class Content extends Model
|
||||
* @param bool $handler
|
||||
* @param bool $status
|
||||
* @param bool $joinAuthor
|
||||
* @param bool $joinParent
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@@ -186,9 +187,10 @@ class Content extends Model
|
||||
{
|
||||
$query = DB::table('contents')
|
||||
->select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id')
|
||||
->where('contents.status', '<>', self::STATUS_DELETED)
|
||||
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
||||
->join('modules', 'modules.handler', '=', 'contents.module_handler')
|
||||
->whereNull('contents.deleted_at')
|
||||
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
||||
->where('modules.enabled', 1)
|
||||
->orderBy('created_at', 'DESC');
|
||||
|
||||
// filter results using handler
|
||||
@@ -439,7 +441,7 @@ class Content extends Model
|
||||
public function view()
|
||||
{
|
||||
$this->timestamps = false;
|
||||
$this->viewed ++;
|
||||
$this->viewed++;
|
||||
$this->save();
|
||||
$this->timestamps = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user