Skip to content

Instantly share code, notes, and snippets.

@phreakin
Created May 12, 2023 08:14
Show Gist options
  • Save phreakin/80f3f5ebe3b7a42bef27fa818e7300ce to your computer and use it in GitHub Desktop.
Save phreakin/80f3f5ebe3b7a42bef27fa818e7300ce to your computer and use it in GitHub Desktop.
Page.php
<?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