Created
August 11, 2021 16:35
-
-
Save owenconti/5030184196ea5f79c5522e721a87d2d5 to your computer and use it in GitHub Desktop.
Orbit relationships
This file contains 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 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'); | |
} | |
} |
This file contains 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 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