Created
May 12, 2023 08:14
-
-
Save phreakin/80f3f5ebe3b7a42bef27fa818e7300ce to your computer and use it in GitHub Desktop.
Page.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use App\Base\SluggableModel; | |
use DateTimeInterface; | |
use Illuminate\Database\Eloquent\Factories\HasFactory; | |
use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
use Illuminate\Database\Eloquent\Relations\HasMany; | |
class Page extends SluggableModel | |
{ | |
use HasFactory; | |
/** | |
* @param string $string | |
* @param null $null | |
* @return Page | |
*/ | |
public static function where(string $string, null $null): Page | |
{ | |
return new self(); | |
} | |
/** | |
* @return BelongsTo | |
*/ | |
public function parent(): BelongsTo | |
{ | |
return $this->belongsTo(__CLASS__); | |
} | |
/** | |
* @return HasMany | |
*/ | |
public function children(): HasMany | |
{ | |
return $this->hasMany(__CLASS__, 'parent_id', 'id'); | |
} | |
/** | |
* @return string | |
*/ | |
public function getLinkAttribute(): string | |
{ | |
return route('page', ['pSlug' => $this->slug]); | |
} | |
/** | |
* Prepare a date for array / JSON serialization. | |
* | |
* @param DateTimeInterface $date | |
* @return string | |
*/ | |
protected function serializeDate(DateTimeInterface $date): string | |
{ | |
return $date->format('Y-m-d H:i:s'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment