2018-09-04 14:51:04 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2018-11-13 16:21:58 +00:00
|
|
|
|
// 1. To specify package’s class you are using
|
2018-09-06 15:58:54 +00:00
|
|
|
|
use App\Models\ModelTrait;
|
2018-09-12 15:30:42 +00:00
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-08-27 09:15:23 +00:00
|
|
|
|
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
|
|
|
|
|
use Astrotomic\Translatable\Translatable;// use Dimsav\Translatable\Translatable;
|
2018-09-04 14:51:04 +00:00
|
|
|
|
|
2019-08-27 09:15:23 +00:00
|
|
|
|
class Page extends Model implements TranslatableContract
|
2018-09-04 14:51:04 +00:00
|
|
|
|
{
|
2018-09-06 15:58:54 +00:00
|
|
|
|
use ModelTrait;
|
2018-11-13 16:21:58 +00:00
|
|
|
|
use Translatable; // 2. To add translation methods
|
|
|
|
|
|
|
|
|
|
// 3. To define which attributes needs to be translated
|
|
|
|
|
public $translatedAttributes = ['title', 'description'];
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-04 14:51:04 +00:00
|
|
|
|
* The database table used by the model.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $table;
|
2018-11-13 16:21:58 +00:00
|
|
|
|
|
2018-09-04 14:51:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* The guarded field which are not mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default values for attributes.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $attributes = [
|
|
|
|
|
'created_by' => 1,
|
|
|
|
|
];
|
|
|
|
|
|
2018-09-12 15:30:42 +00:00
|
|
|
|
//You can specify default eager loaded relationships using the $with property on the model.
|
|
|
|
|
//https://stackoverflow.com/questions/25674143/laravel-whenever-i-return-a-model-always-return-a-relationship-with-it
|
2018-09-04 14:51:04 +00:00
|
|
|
|
protected $with = ['owner'];
|
|
|
|
|
|
|
|
|
|
public function __construct(array $attributes = [])
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($attributes);
|
2018-09-12 15:30:42 +00:00
|
|
|
|
$this->table = 'pages'; //config('module.pages.table');
|
2018-09-13 12:03:17 +00:00
|
|
|
|
// $this->defaultLocale = 'de';
|
2018-09-04 14:51:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function owner()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 15:30:42 +00:00
|
|
|
|
/**
|
2018-09-06 15:58:54 +00:00
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getActionButtonsAttribute()
|
|
|
|
|
{
|
|
|
|
|
return '<div class="btn-group action-btn">
|
2018-09-12 15:30:42 +00:00
|
|
|
|
' . $this->getEditButtonAttribute('page', 'settings.page.edit') . '
|
|
|
|
|
' . $this->getViewButtonAttribute() . '
|
2018-09-06 15:58:54 +00:00
|
|
|
|
</div>';
|
2018-09-12 15:30:42 +00:00
|
|
|
|
// '.$this->getDeleteButtonAttribute('page', 'settings.page.destroy').'
|
2018-09-06 15:58:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 15:30:42 +00:00
|
|
|
|
/**
|
2018-09-06 15:58:54 +00:00
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getViewButtonAttribute()
|
|
|
|
|
{
|
2018-09-10 13:09:10 +00:00
|
|
|
|
return '<a target="_blank" href="
|
2018-09-12 15:30:42 +00:00
|
|
|
|
' . route('frontend.pages.show', $this->page_slug) . ' " class="btn btn-flat btn-default">
|
2018-09-06 15:58:54 +00:00
|
|
|
|
<i data-toggle="tooltip" data-placement="top" title="View Page" class="fa fa-eye"></i>
|
|
|
|
|
</a>';
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 15:30:42 +00:00
|
|
|
|
/**
|
2018-09-06 15:58:54 +00:00
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getStatusLabelAttribute()
|
|
|
|
|
{
|
|
|
|
|
if ($this->isActive()) {
|
2018-09-12 15:30:42 +00:00
|
|
|
|
return "<label class='label label-success'>" . trans('labels.general.active') . '</label>';
|
2018-09-06 15:58:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 15:30:42 +00:00
|
|
|
|
return "<label class='label label-danger'>" . trans('labels.general.inactive') . '</label>';
|
2018-09-06 15:58:54 +00:00
|
|
|
|
}
|
2018-09-12 15:30:42 +00:00
|
|
|
|
|
2018-09-04 14:51:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isActive()
|
|
|
|
|
{
|
|
|
|
|
return $this->status == 1;
|
|
|
|
|
}
|
|
|
|
|
}
|