Skip to content

Instantly share code, notes, and snippets.

@owenconti
Created August 11, 2021 16:35
Show Gist options
  • Save owenconti/5030184196ea5f79c5522e721a87d2d5 to your computer and use it in GitHub Desktop.
Save owenconti/5030184196ea5f79c5522e721a87d2d5 to your computer and use it in GitHub Desktop.
Orbit relationships
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Orbit\Concerns\Orbital;
class Category extends Model
{
use Orbital;
protected $guarded = [];
public static function schema(Blueprint $table)
{
$table->string('slug');
$table->string('title');
}
public function getUrlAttribute()
{
return url("category/{$this->slug}");
}
public function getKeyName()
{
return 'slug';
}
public function getIncrementing()
{
return false;
}
public function pages()
{
return $this->hasMany(Page::class, 'category_slug', 'slug');
}
}
<?php
namespace App\Models;
use ArchTech\Pages\Page as BasePage;
use Illuminate\Database\Schema\Blueprint;
class Page extends BasePage
{
public static function schema(Blueprint $table)
{
$table->string('slug');
$table->string('title');
$table->longText('content');
$table->text('excerpt')->nullable();
$table->string('type');
$table->string('category_slug')->nullable();
}
public function getUrlAttribute()
{
return url($this->slug);
}
public function category()
{
return $this->belongsTo(Category::class, 'category_slug');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment