2021-03-06 18:51, Grzegorz Brzęczyszczykiewicz rašė:
Dabar problemą sprendžia štai toks pargiuvęs PHP /Laravel kodas, bet
kažkodėl norwčiau užkrauti tą darbą SQL'ui:
$tmp_documents = \App\Document::where('project_id',
$project->id)->orderBy('follows_id', 'asc')->get();
$documents = collect([$tmp_documents->first()]);
$prev_document = $tmp_documents->first()->id;
$tmp = $tmp_documents->slice(1);
while (!$tmp->isEmpty()) {
$doc = $tmp->where('follows_id',$prev_document)->first();
$prev_document = $doc->id;
$documents->push($doc);
$tmp = $tmp->diff([$doc]);
}
--
Grzegorz
Chrząszczyrzewoszyce, powiat Łękołody