67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Class Content
|
|
*/
|
|
class Content extends Model
|
|
{
|
|
public $timestamps = true;
|
|
protected $fillable = [
|
|
'user_id',
|
|
'module_handler',
|
|
'published_from',
|
|
'published_to',
|
|
'title_photo',
|
|
'title',
|
|
'url',
|
|
'meta_keywords',
|
|
'meta_description',
|
|
'content',
|
|
'module_settings',
|
|
'status'
|
|
];
|
|
protected $guarded = [];
|
|
const STATUS_DELETED = 'deleted';
|
|
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');
|
|
}
|
|
} |