63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class TravelPageGuide extends Model
|
|
{
|
|
protected $connection = 'mysql_stern';
|
|
|
|
protected $table = 'page';
|
|
|
|
protected $fillable = [
|
|
'slug',
|
|
'status',
|
|
'show_in_navi',
|
|
'order',
|
|
'title',
|
|
'pagetitle',
|
|
'description',
|
|
'keywords',
|
|
'content_new',
|
|
'travel_guide_content_id',
|
|
];
|
|
|
|
|
|
private static $pages = [];
|
|
|
|
public static function getPageGuides($setKey = false){
|
|
$values = self::where('model', 'travel_guide')->where('lvl', 1)->orderBy('order')->get();
|
|
|
|
foreach ($values as $value){
|
|
self::$pages[] = $value;
|
|
|
|
$value->checkChilds();
|
|
if($childs = $value->getChilds()){
|
|
foreach ($childs as $child){
|
|
$ret[] = $child;
|
|
}
|
|
}
|
|
}
|
|
|
|
return self::$pages;
|
|
}
|
|
|
|
public function checkChilds(){
|
|
if($childs = $this->getChilds()){
|
|
foreach ($childs as $child){
|
|
self::$pages[] = $child;
|
|
$child->checkChilds();
|
|
}
|
|
}
|
|
}
|
|
public function getChilds(){
|
|
return TravelPageGuide::where('parent_id', $this->id)->where('lvl', ($this->lvl+1))->orderBy('order')->get();
|
|
}
|
|
|
|
public function getContentNewAttribute()
|
|
{
|
|
return isset($this->attributes['content_new']) ? $this->attributes['content_new'] : $this->attributes['content'];
|
|
}
|
|
|
|
}
|