function stampa($komentari, $a) { if ($komentari) { foreach ($komentari as $komentar) { array_push($a, $komentar); $sledeci = App\Comment::where('parent_id', '=', $komentar->id)->where('article_id', '=', $komentar->article_id)->get(); $a = stampa($sledeci, $a); } } return $a; }
/** * Run the database seeds. * * @return void */ public function run() { factory(App\Project::class, 20)->create()->each(function ($project) { $max = rand(5, 10); for ($i = 0; $i < $max; $i++) { $project->goal()->save(factory(App\Goal::class)->make()); } $max = rand(5, 10); for ($i = 0; $i < $max; $i++) { $project->reward()->save(factory(App\Reward::class)->make()); } $max = rand(5, 20); for ($i = 0; $i < $max; $i++) { $project->payment()->save(factory(App\Payment::class)->make()); } $max = rand(5, 20); for ($i = 0; $i < $max; $i++) { $project->comment()->save(factory(App\Comment::class)->make(['type' => 1])); } $max = rand(5, 20); for ($i = 0; $i < $max; $i++) { $project->updates()->save(factory(App\Content::class)->make(['type' => 3])); } }); $payments = App\Payment::where('value', 0)->get(); foreach ($payments as $p) { $project = App\Project::find($p->project_id); $reward = $project->reward()->orderBy(DB::raw('RAND()'))->take(1)->first(); $p->value = $reward->value; $p->reward_id = $reward->id; $p->save(); } $comments = App\Comment::where('type', 1)->where('reply_id', 1)->get(); foreach ($comments as $c) { $parents = App\Comment::where('type', 1)->where('item_id', $c->item_id)->orderByRaw("RAND()")->first(); if ($parents) { $c->reply_id = $parents->id; $c->save(); } } }
public function testDeleteWithRelations() { // one-to-many, many-to-many App\Post::find(1)->deleteWithRelations(); self::assertEquals(App\Post::where('id', 1)->count(), 0); self::assertEquals(App\Comment::where('post_id', 1)->count(), 0); self::assertEquals(DB::table('lv_post_tag')->where('post_id', 1)->count(), 0); // one-to-one App\Post::getDeleteDescriptor()->removeDescription('comments'); App\Comment::getDeleteDescriptor()->add('post'); App\Comment::find(4)->deleteWithRelations(); self::assertEquals(App\Comment::where('id', 4)->count(), 0); self::assertEquals(App\Post::where('id', 2)->count(), 0); // db rollback $this->rollback(); }