FEATURE: add overview to all static pages
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Class Content
|
||||
@@ -29,4 +30,38 @@ class Content extends Model
|
||||
const STATUS_DRAFT = 'draft';
|
||||
const STATUS_PROTECTED = 'protected';
|
||||
const STATUS_PUBLIC = 'public';
|
||||
|
||||
/**
|
||||
* Getter for overview of all content pages of given handler (module type)
|
||||
*
|
||||
* @param $handler
|
||||
* @param bool $joinAuthor
|
||||
*
|
||||
*/
|
||||
public function getByType($handler, $joinAuthor = false)
|
||||
{
|
||||
$query = DB::table('contents')
|
||||
->select('contents.*')
|
||||
->where('contents.status', '<>', self::STATUS_DELETED)
|
||||
->where('module_handler', $handler)
|
||||
->orderBy('created_at');
|
||||
|
||||
// join user email and user name to results when needed
|
||||
if ($joinAuthor) {
|
||||
$query = $query->join('users', 'users.id', '=', 'contents.user_id')
|
||||
->select('contents.*', 'users.name AS author_name', 'users.email AS author_email');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark relationship with users table
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo('App\Models\User', 'user_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user