Skip to content

Instantly share code, notes, and snippets.

@heryvandoro
Created May 28, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heryvandoro/71710141f5552294076a23b985a48991 to your computer and use it in GitHub Desktop.
Save heryvandoro/71710141f5552294076a23b985a48991 to your computer and use it in GitHub Desktop.
<?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