webseite funktioniert, pay sdk, blog backend funktioniert
This commit is contained in:
@@ -2,24 +2,44 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
use Stephenjude\FilamentBlog\Models\Category as BaseCategory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BlogCategory extends BaseCategory
|
||||
class BlogCategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $translatable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
protected $table = 'blog_categories';
|
||||
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'is_visible',
|
||||
'translations',
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_visible' => 'boolean',
|
||||
'name' => 'array',
|
||||
'description' => 'array',
|
||||
];
|
||||
|
||||
public function posts(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlogPost::class, 'blog_category_id');
|
||||
}
|
||||
|
||||
public function scopeIsVisible(Builder $query)
|
||||
{
|
||||
return $query->where('is_visible', true);
|
||||
}
|
||||
|
||||
public function scopeIsInvisible(Builder $query)
|
||||
{
|
||||
return $query->where('is_visible', false);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
use Stephenjude\FilamentBlog\Models\Post as BasePost;
|
||||
|
||||
class BlogPost extends BasePost
|
||||
class BlogPost extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
|
||||
protected $table = 'blog_posts';
|
||||
|
||||
protected $translatable = [
|
||||
'title',
|
||||
'excerpt',
|
||||
@@ -21,7 +26,6 @@ class BlogPost extends BasePost
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'blog_author_id',
|
||||
'blog_category_id',
|
||||
'slug',
|
||||
'banner',
|
||||
@@ -29,4 +33,33 @@ class BlogPost extends BasePost
|
||||
'is_published',
|
||||
'translations',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'published_at' => 'date',
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'banner_url',
|
||||
];
|
||||
|
||||
public function bannerUrl(): Attribute
|
||||
{
|
||||
return Attribute::get(fn () => $this->banner ? asset(Storage::url($this->banner)) : '');
|
||||
}
|
||||
|
||||
public function scopePublished(Builder $query)
|
||||
{
|
||||
return $query->whereNotNull('published_at')->where('is_published', true);
|
||||
}
|
||||
|
||||
public function scopeDraft(Builder $query)
|
||||
{
|
||||
return $query->whereNull('published_at');
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(BlogCategory::class, 'blog_category_id');
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Tags\Tag;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
use Stephenjude\FilamentBlog\Models\Tag as BaseTag;
|
||||
|
||||
class BlogTag extends BaseTag
|
||||
class BlogTag extends Tag
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
|
||||
|
||||
@@ -40,7 +40,32 @@ class Package extends Model
|
||||
'features' => 'array',
|
||||
];
|
||||
|
||||
// features handled by $casts = ['features' => 'array']
|
||||
|
||||
protected function features(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function ($value) {
|
||||
if (is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
|
||||
if (is_string($decoded)) {
|
||||
$decoded = json_decode($decoded, true);
|
||||
}
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function eventPackages(): HasMany
|
||||
{
|
||||
@@ -77,4 +102,4 @@ class Package extends Model
|
||||
'max_events_per_year' => $this->max_events_per_year,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user