Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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