I have two tables Categories:
Schema::create('categories', function(Blueprint $table)
{
$table->increments('id');
$table->integer('parent_id')->unsigned()->nullable();
$table->foreign('parent_id')->references('id')->on('categories')->onDelete('set null');
$table->integer('position', false, true);
$table->integer('depth', false, true);
$table->timestamps();
$table->softDeletes();
});
And Categories Closure:
Schema::create('category_closures', function(Blueprint $table)
{
$table->increments('id');
$table->integer('ancestor', false, true);
$table->foreign('ancestor')->references('id')->on('categories')->onDelete('cascade');
$table->integer('descendant', false, true);
$table->foreign('descendant')->references('id')->on('categories')->onDelete('cascade');
$table->integer('depth', false, true);
});
Entries in Categories table is:
ID parent_id position depth
1 null 0 0
2 null 1 0
3 1 0 1
4 3 0 2
How to make query with correct order(flat, not tree list):
ID 1,3,4,2 ?