public function parent()
{
return $this->belongsTo('AppCourseModule','parent_id')->where('parent_id',0);
}
public function children()
{
return $this->hasMany('AppCourseModule','parent_id');
}
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class Test extends Model
{
use HasFactory;
protected $parentColumn = 'parent_id';
public function parent()
{
return $this->belongsTo(Test::class,$this->parentColumn);
}
public function children()
{
return $this->hasMany(Test::class, $this->parentColumn);
}
public function allChildren()
{
return $this->children()->with('allChildren');
}
}