Feedback in V3

This commit is contained in:
Kevin Adametz 2018-12-27 17:38:05 +01:00
parent 765d6a2f6b
commit 6e0c7e8706
19 changed files with 1141 additions and 491 deletions

74
app/Models/Feedback.php Normal file
View file

@ -0,0 +1,74 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use HTMLHelper;
class Feedback extends Page
{
protected $table = 'page';
public static function boot()
{
parent::boot();
static::addGlobalScope(function ($query) {
$query->where('model', 'feedback');
$query->orderBy('lvl', 'ASC');
$query->orderBy('date', 'DESC');
});
}
public function parent()
{
return $this->belongsTo('App\Models\Feedback', 'owner');
}
public function getParent()
{
if ($this->lvl == 2) {
$this->parent();
}
return false;
}
public function setContentAttribute($value)
{
if (!$value) {
$this->attributes['content'] = $value;
} else {
$this->attributes['content'] = HTMLHelper::filterHTML($value, ['src' => ['removeHost']], true);
}
}
public function getParentsArray(){
//lvl 0
return Page::where('model', 'feedback')->where('lvl', 1)->get()->pluck('title', 'id');
}
//$feedbacks = Feedback::where('lvl', 1)->get();
public function getDateRow()
{
return$this->attributes['date'];
}
public function getDateAttribute()
{
return isset($this->attributes['date']) ? Carbon::parse($this->attributes['date'])->format("d.m.Y") : '';
}
public function setDateAttribute($value)
{
if (!$value) {
$this->attributes['date'] = null;
} else {
$this->attributes['date'] = (new Carbon($value))->format('Y-m-d');
}
}
}

13
app/Models/Page.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'page';
}