Пример #1
0
 public function run()
 {
     // FKの無効化
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('votes')->truncate();
     $faker = Faker::create('en_US');
     for ($i = 0; $i < 100; $i++) {
         Vote::create(['title' => $faker->sentence(), 'body' => $faker->paragraph(), 'is_published' => rand(0, 1), 'created_at' => Carbon::today()]);
     }
     // FKを元に戻す
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Пример #2
0
 public function run()
 {
     // FKの無効化
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('choices')->truncate();
     $faker = Faker::create('ja_JP');
     $votes = Vote::all()->toArray();
     foreach ($votes as $key => $vote) {
         Choice::create(['chc1' => $faker->sentence(), 'chc2' => $faker->sentence(), 'chc3' => $faker->sentence(), 'chc4' => $faker->sentence(), 'chc5' => $faker->sentence(), "vote_id" => $vote['id'], 'created_at' => Carbon::today(), 'isDispOther' => rand(0, 1)]);
     }
     // FKを元に戻す
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Пример #3
0
 public function deleteVote($token, $delete_vote_id)
 {
     $userId = User::select("id")->where("token", "=", $token)->first()['id'];
     if (!$userId) {
         return \Response::json(["error" => "400", "message" => "invalid token error."]);
     }
     Log::info("token : {$token}. voteid : {$delete_vote_id}");
     $vote = Vote::where('id', '=', $delete_vote_id)->where('user_id', '=', User::where('token', '=', $token)->first()["id"])->first();
     if (!$vote) {
         return \Response::json(["error" => "400", "message" => "this vote is not exists."]);
     }
     $vote->delete();
     return \Response::json(["status" => "200", "id" => $delete_vote_id]);
 }