Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $with = ["sub_categories"];
public function sub_categories(){
return $this->hasMany("App\Models\Category", "parent_id", "id");
}
public function parent(){
return $this->belongsTo("App\Models\Category", "parent_id", "id");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.