104 lines
2.7 KiB
PHP
104 lines
2.7 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
|
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Page extends Model
|
|
{
|
|
use CrudTrait;
|
|
use Sluggable;
|
|
use SluggableScopeHelpers;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| GLOBAL VARIABLES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
protected $table = 'pages';
|
|
protected $primaryKey = 'id';
|
|
public $timestamps = true;
|
|
// protected $guarded = ['id'];
|
|
protected $fillable = ['template', 'name', 'title', 'slug', 'content', 'extras'];
|
|
// protected $hidden = [];
|
|
// protected $dates = [];
|
|
protected $fakeColumns = ['extras'];
|
|
|
|
/**
|
|
* Return the sluggable configuration array for this model.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function sluggable()
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'slug_or_title',
|
|
],
|
|
];
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| FUNCTIONS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
public function getTemplateName()
|
|
{
|
|
return str_replace('_', ' ', title_case($this->template));
|
|
}
|
|
|
|
public function getPageLink()
|
|
{
|
|
return url($this->slug);
|
|
}
|
|
|
|
public function getOpenButton()
|
|
{
|
|
return '<a class="btn btn-default btn-xs" href="'.$this->getPageLink().'" target="_blank">'.
|
|
'<i class="fa fa-eye"></i> '.trans('backpack::pagemanager.open').'</a>';
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| RELATIONS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| SCOPES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| ACCESORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
// The slug is created automatically from the "name" field if no slug exists.
|
|
public function getSlugOrTitleAttribute()
|
|
{
|
|
if ($this->slug != '') {
|
|
return $this->slug;
|
|
}
|
|
|
|
return $this->title;
|
|
}
|
|
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| MUTATORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
}
|