111 lines
2.3 KiB
PHP
111 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class Setting
|
|
*
|
|
* @property int $id
|
|
* @property string|null $identifier
|
|
* @property string $slug
|
|
* @property int $referenz
|
|
* @property string|null $action
|
|
* @property string|null $object
|
|
* @property string|null $content
|
|
* @property int $status
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class Setting extends Model
|
|
{
|
|
use Sluggable;
|
|
|
|
protected $table = 'settings';
|
|
|
|
protected $casts = [
|
|
'referenz' => 'int',
|
|
'status' => 'int',
|
|
'object' => 'array'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'identifier',
|
|
'slug',
|
|
'referenz',
|
|
'action',
|
|
'object',
|
|
'full_text',
|
|
'text',
|
|
'status',
|
|
'type'
|
|
];
|
|
|
|
protected static $types = [
|
|
'object' => 'Object',
|
|
'full_text' => 'Full Text',
|
|
'text' => 'Text',
|
|
];
|
|
|
|
public function sluggable()
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'name'
|
|
]
|
|
];
|
|
}
|
|
public static function getContentBySlug($slug){
|
|
$content = self::whereSlug(trim($slug))->first();
|
|
if($content){
|
|
switch ($content->type){
|
|
case 'object':
|
|
return $content->object;
|
|
break;
|
|
case 'full_text':
|
|
return $content->full_text;
|
|
break;
|
|
case 'text':
|
|
return $content->text;
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function setContentBySlug($slug, $value, $type = "full_text"){
|
|
|
|
$content = self::whereSlug(trim($slug))->first();
|
|
if(!$content) {
|
|
$content = self::create([
|
|
'slug' => $slug,
|
|
'type' => $type,
|
|
]);
|
|
}
|
|
$content->type = $type;
|
|
switch ($content->type){
|
|
case 'object':
|
|
$content->object = $value;
|
|
break;
|
|
case 'full_text':
|
|
$content->full_text = $value;
|
|
break;
|
|
case 'text':
|
|
$content->text = $value;
|
|
break;
|
|
}
|
|
|
|
$content->save();
|
|
return $content;
|
|
}
|
|
|
|
}
|